Marching a call from one thread to a specific other thread is very nontrivial. It is not possible to arbitrarily interrupt a stream and force it to execute some code. This causes terrible reconnection issues. Trying to protect against this with, say, a semaphore is guaranteed to cause a dead end.
The target thread must interact, it must be "inactive" and not actively change the state of the program. A common mechanism for this is a thread-safe queue. The thread for creating events queues the request; the target thread needs a loop that reads the requests from the queue and executes them. Maybe this sounds familiar, yes, that the user interface thread of the program works.
source share