Pithikos / C-Thread-Pool

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

function type for the worker task #5

Closed dvhh closed 9 years ago

dvhh commented 9 years ago

task are of type

void *(*function_p)(void*)

http://cdecl.ridiculousfish.com/?q=void+*%28*function_p%29%28void*%29

where I believe they should be

void (*function_p)(void*)

http://cdecl.ridiculousfish.com/?q=void+%28*function_p%29%28void*%29

I believe that I causes a bus error when you try to put the first type on the pool and the manager would try to pull them from the pool, plus there is no way to return whatever the worker return, except via output parameters

Pithikos commented 9 years ago

Do you have a specific issue with the code? What do you mean with 'bus error'?

There shouldn't be a problem no matter if a function returns void or a pointer to void. You are not supposed to return anything from a function added to the pool anyway. It's just how threadpools work. To whom would they return for example? The manager? The user? In both cases things would become way too complex for no benefit since you would need synchronisation mechanisms everywhere and ways for the user to get those return values - really ugly.

If you want to 'return' something from your task simply use globals. People tend to have a bad look on globals but in cases like this, globals are the best way to do things. You can even use a mutex on your global so that many tasks in the threadpool work on the same thing. That makes things simpler and you know exactly what is going on.