If I am going to create a pthread for the following function.
Assume everything is properly delared.
pthread_create(&threadId, &attr, (void * (*)(void*))function, //what should be the arguments for here??);
int a = 0;
int b = 1;
//c and d are global variables.
void function(int a, int b){
c = a;
d = b;
}
This does not work. function() has to take exactly one argument. That's why you have to do this:
(void * ()(void))
You're telling your compiler "no, seriously, this function only takes one argument", which of course it doesn't.
What you have to do instead is pass a single argument (say a pointer to a struct) which gets you the information you need.
Edit: See here for an example: number of arguments for a function in pthread
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With