pthreads: intro `ThreadPool::join_all`
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 3 Feb 2017 19:37:22 +0000 (14:37 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 3 Feb 2017 22:45:02 +0000 (17:45 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/pthreads/threadpool.nit

index cbb6594..927cdbf 100644 (file)
@@ -42,6 +42,15 @@ class ThreadPool
                queue.push(task)
                cond.signal
        end
+
+       # Join all threads, waiting for all tasks to be completed
+       fun join_all do
+               # Wait
+               for t in threads do t.join
+
+               # Reset
+               threads.clear
+       end
 end
 
 # A Thread running in a threadpool