Thread: Threaded callbacks...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Threaded callbacks...

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Since callbacks use a function pointer, I can be assured that the right thread instance will be called back, right?
    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.

    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Callbacks
    By Dae in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 05:40 AM
  2. Callbacks?
    By DavidDobson in forum C Programming
    Replies: 5
    Last Post: 10-03-2008, 12:59 PM
  3. Going from single-threaded to multi-threaded
    By Dino in forum C Programming
    Replies: 11
    Last Post: 03-23-2008, 01:14 PM
  4. Doing callbacks
    By Elysia in forum C++ Programming
    Replies: 7
    Last Post: 02-06-2008, 03:16 PM
  5. Callbacks
    By pradeepkrao in forum C++ Programming
    Replies: 5
    Last Post: 09-13-2002, 10:30 PM