+ 1
How to pass argument to thread pool function
I tried to create a sample thread pool as below: https://www.sololearn.com/compiler-playground/covRjcxiT4nn This is working fine, but when I try to add an int type input to func, it does not work as below: https://www.sololearn.com/compiler-playground/c44cZN9RJG8j
7 ответов
+ 6
https://code.sololearn.com/c3RkVtjM4U8G/?ref=app
changes : line 43 ,46,108
you should pass function as argument not after evaluating it , as it will pass the returned value not function pointer to the thread pool ..
+ 4
Ketan Lalcheta
actually i have no idea what youre trying to do ...
but the point is you shouldn't pass function after evaluating ...
for line 48 you could just store a map of std::function and its argument.
for line 43 jobFunc(0) here we should pass in something since it cant accept void .. i dunno what youre trying to do..
explain further because im a bit lazy to read full code ...
0
Link to code added into question description for mob app :
https://code.sololearn.com/covRjcxiT4nn/?ref=app
https://code.sololearn.com/c44cZN9RJG8j/?ref=app
0
Thanks ..
What about line 48 ?
fn(i);
Does it not call function ? We need to just pass it to queue...right ?
0
Also why 0 is passed on line 48 ?
jobFunc(0); // arg should be int not void ...
0
I got your point of not passing an evalualted fun ...
What i need to do is to call function as job with id I passed from main function
0
Basically for loop index i passed as argument should be used to call jobFun, not zero...how to get that int there