I have two different threads. the first one is the main thread that must handle the gui operations. the second one is a network thread which listens the related tcp ports. I need network thread to invoke methods in a way that they will run in the main thread. how can I achieve this without using a message queue mechanism?
Share
How I would do it in your case is to is tell the other thread to schedule a function on its event queue. Arguments to that function are bound in with the function that is sent.
Like for example in the network code:
All GUI frameworks and most networking frameworks allow you to do that.
One issue might be the binding of additional parameters for libraries that only give you C callbacks. My suggestion is to write a “wrapper” function that allows you to pass std::functions into the callback.