Pithikos / C-Thread-Pool

A minimal but powerful thread pool in ANSI C
MIT License
2.06k stars 603 forks source link

getting error cannot convert to a pointer type when passing a struct as args #42

Closed ghost closed 7 years ago

ghost commented 7 years ago

my code requires me to pass a struct to task for the threads and i get this error convert to a pointer type

My code is

struct Tuple { int a; int b; }; void searchTree(struct Tuple exvals)

{ int e1 ,e2; e1 = exvals.a; e2 = exvals.b; .............. } void main(int argc, char *argv[]) { struct Tuple expandVals; expandVals = searchANode(currnode);//another function

thpool = thpool_init(numThreads); thpool_addwork(thpool, (void)searchTree, (void_)expandVals);

puts("Killing threadpool");
thpool_destroy(thpool);

}

Pithikos commented 7 years ago

Which exactly is the error code?

ghost commented 7 years ago

In function ‘main’: p3d.c:163:9: error: cannot convert to a pointer type thpool_addwork(thpool, (void)searchTree, (void_)expandVals);

Pithikos commented 7 years ago

Have a look at the example at https://github.com/Pithikos/C-Thread-Pool/blob/master/example.c and the tests at https://github.com/Pithikos/C-Thread-Pool/tree/master/tests/src

You need to pass a pointer to void. In your case I assume something like (void*)searchTree

ghost commented 7 years ago

My code is this and I followed the example and passed void pointer to both the function and argument which in my case is a struct . Its just that when i post this comment earlier, it removed * from my code where i have passed the void pointer.So Im posting my code again

struct Tuple { int a; int b; }; void searchTree(struct Tuple exvals)

{ int e1 ,e2; e1 = exvals.a; e2 = exvals.b; .............. } void main(int argc, char *argv[]) { struct Tuple expandVals; expandVals = searchANode(currnode);//another function

thpool = thpool_init(numThreads); thpool_add_work(thpool, (void * )searchTree, (void * )expandVals);

puts("Killing threadpool"); thpool_destroy(thpool); }

ghost commented 7 years ago

Issue resolved ,