From 6c081144e5bcf31edece0806c38d63c97257cc4c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 26 Jan 2018 14:32:06 -0800 Subject: ThreadPool refactoring (#1389) Refactor ThreadPool code for clarity and to fix some bugs with using the pool from different threads in parallel. We have a singleton pool, and need to ensure it is created only once and used only by one thread at a time. This model is a simple way to ensure we use a number of threads equal to the number of cores, more or less (a pool per Module might lead to number of cores * number of Modules being optimized). This refactoring adds a parent pointer in the worker threads (giving them direct access to the pool makes it simpler to make sure that pool and thread creation and teardown are threadsafe). This commit also adds proper locking around pool creation and pool usage. --- test/example/cpp-threads.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/example/cpp-threads.txt (limited to 'test/example/cpp-threads.txt') diff --git a/test/example/cpp-threads.txt b/test/example/cpp-threads.txt new file mode 100644 index 000000000..2c638aaab --- /dev/null +++ b/test/example/cpp-threads.txt @@ -0,0 +1,4 @@ +create threads... +threads running in parallel... +waiting for threads to join... +all done. -- cgit v1.2.3