First time using threads in C++. I've been looking at using boost which is very confusing for me. Basically all I'm trying to do is:
- Create a worker thread that does some work asynchronously. Continue main thread while work is being done.
- When the worker thread is done, fire a callback function with some results that executes in the main thread context.
So something similar to thread handling in C#.
There doesn't seem to be any support for 2. Using an io_service together with an async function, and thereafter using run() on the io_service seems to block the main thread. So not very asynchronous.
I've tried using boost::future as per the example here: Using boost::future with "then" continuations
Here the "then" continuation is done in a separate thread, not the main thread, so not what I'm after. Is there any way to alter this? Using boost::launch::deferred and wait() makes the call synchronous, so that doesn't help either. Same with just using get() on the boost::future construct.
It seems the only option is to create a mutex-locked shared event queue, and just poll it continuously for new data in the main thread?