General query about Callback functions and Threads General query about Callback functions and Threads multithreading multithreading

General query about Callback functions and Threads


As a general rule, function calls are always made in the caller's context (thread). It doesn't matter whether the callee is a function, member function, functor object, or anything else.

In other words, when the thread calls your callback, the call happens in the thread. The main thread is not stopped in order to execute the callback. In fact, it isn't involved in any way with the execution of the callback.

Various frameworks provide tricks to make it seem as if one thread can call another directly, but this is always done in a cooperative way through some kind of marshalled message-passing mechanism. Threads generally don't twiddle each other's stacks.