Hello,
I'm using an external library that I need to register callbacks with, and I need to do this from within a thread. Since callbacks use a function pointer, I can be assured that the right thread instance will be called back, right?
Thanks.
Hello,
I'm using an external library that I need to register callbacks with, and I need to do this from within a thread. Since callbacks use a function pointer, I can be assured that the right thread instance will be called back, right?
Thanks.
Well that depends entirely on the nature of the library in question.
If you take something simple like the qsort() function, which takes a function pointer parameter, then that function is executed in the same context as the thread calling qsort().
But if it's a complicated library (say the Apache web server), then who knows.
You could try actually naming your library, you might get a more specific answer.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Calling a function from C doesn't involve any thread trickery - the thread that calls the function will be the one the function runs in.Since callbacks use a function pointer, I can be assured that the right thread instance will be called back, right?
The only way you can be assured that the code runs in the "right" thread (whatever that means for your application) is if you or your library does the work necessary to assure you of it - check its documentation/ask on its mailing list. Otherwise, to guarantee all callbacks are invoked from a specific thread, you'll have to manually implement some sort of message queue that dispatches from your thread.