You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I could not figure out how it is ment to wait for all Tasks to finish.
If i use stop - the Threads get deleted and the threadpool ends.
Isn't there something like p.WaitForEverythingDone()?
Currently I use this in the main thread:
while (p.n_idle() < THREAD_COUNT )
{
}
But thats not really a good idea to burn 1 cpu core just for waiting?
The text was updated successfully, but these errors were encountered:
Yeah, don't use stop() :-)
This is what I do:
In the main thread, create an atomic int set to 0 (call it thread_count, say). This atomic int is passed to the thread (each thread) as a std::ref() and the thread updates thread_count (adds 1) when it's finished processing, i.e. at the end of the function.
The main thread just waits for the atomic int to match what I expected it to be (10 for 10 threads, say)
while (thread_count < 10) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
This way, somewhere else in the program, using the same thread pool, but (say) doing physics, can keep using threads without interfering.
Sorry for writing this as an issue.
I could not figure out how it is ment to wait for all Tasks to finish.
If i use stop - the Threads get deleted and the threadpool ends.
Isn't there something like p.WaitForEverythingDone()?
Currently I use this in the main thread:
while (p.n_idle() < THREAD_COUNT )
{
}
But thats not really a good idea to burn 1 cpu core just for waiting?
The text was updated successfully, but these errors were encountered: