For example, I have a main thread, there is created a lot of classes and etc. I have a network part, that wait for client data in separate thread. This “waiter” should run some functions from classes that was created in main thread and this functions should be executed in main thread.
How could I do so? If i call needed methods this way SomeClass::SomeMethod(some_args); from waiter, sure, they executes in secondary thread.
Would be good have something like this:
SomeClass::Invoke(function_pointer); so, the function that function_pointer points on would be executed in main thread? I need an advice for windows OS.
If this is Windows Win32 application, then using the application’s Message processing queue is a common approach.
In the main window of your app you wait for a custom user message, typically it will be something like:
[EDIT]
For a Console application, try using Windows Events. So create a named Event using: