If your main thread works with a message pump, you can send a message somehow to execute a function when your message is received.
Otherwise, there is a simple queue (corresponding lock, of course). Add enough data to the queue so that main_thread_method can be called. (args, etc.). Periodically try a simple queue for new messages in the main thread and process them.
source share