I just had a brief discussion with an intern (which is relevant to the project I'm working on at the moment) regarding callbacks and such and it got me thinking... are callbacks okay to use in a multithreaded environment, more importantly across threads?
I started thinking about it, and I may be missing something on how callbacks work, but wouldn't it be possible for a thread using a callback into another thread (presumably it's parent for most sane purposes) to preempt its parent, err, for lack of any better way to describe it, BY its parent?
I suppose one of the things I am fuzzy on is does the callback run in the context of the thread or in the context of the thread that callback is from (ie: its parent)?
Further, assuming many threads using the same callback, I assume unless the callback in inherently atomic each thread can preempt other threads in the callback, thus again preempting the callback's original context? (Essentially snowballing)
(For me this is just fun stuff to think about, hence why I ask)
I started thinking about it, and I may be missing something on how callbacks work, but wouldn't it be possible for a thread using a callback into another thread (presumably it's parent for most sane purposes) to preempt its parent, err, for lack of any better way to describe it, BY its parent?
I suppose one of the things I am fuzzy on is does the callback run in the context of the thread or in the context of the thread that callback is from (ie: its parent)?
Further, assuming many threads using the same callback, I assume unless the callback in inherently atomic each thread can preempt other threads in the callback, thus again preempting the callback's original context? (Essentially snowballing)
(For me this is just fun stuff to think about, hence why I ask)
