multithreading - C++ / boost : how to signal async task completion? -
i have thread pool executes tasks asynchronously. need wait task complete before proceeding (running task in current thread not allowed, task must run worker thread).
what's easiest way achieve using c++11 or boost?
pool.enqueue([]() { std::this_thread::sleep_for(2s); // task 1 // notify task 1 completion??? std::this_thread::sleep_for(2s); // task 2 }); // wait until task 1 complete???
if have thread pool, either pool should handle dependencies or should chain continuation task first task directly.
otherwise, pool can deadlock. imagine example pool 1 thread. block indefinitely. same can occur many threads given enough task inter dependencies.
Comments
Post a Comment