ThreadPool
                                
                                
                                
                                    ThreadPool copied to clipboard
                            
                            
                            
                        Dead-Lock
- Hi, nbsdx, I try the following code to use the ThreadPool, but it seemed to be a dead-lock there.
 - I use a script to run the program many times, but it occasionally got stuck.
 - The code I wrote is as follows, which could also be found in my branch.
 - Briefly speaking, I just want to do stage-synchronization-computation, where the inner loop is regarded as a stage.
 - I am not able to solve that.
 - Could you please help me with that? Thanks, CHE Yulin
 
#include <thread>
#include <iostream>
#include "ThreadPool.h"
using std::cout;
using std::endl;
int main() {
    using namespace nbsdx::concurrent;
    ThreadPool<20> pool;
    for (auto j = 0; j < 3000; j++) {
        cout << "Round:" << j << endl;
        for (int i = 0; i < 5000; ++i) {
            std::function<int(void)> task_function = [i]() {
                return i * i;
            };
            pool.AddJob(task_function);
        }
        cout << "Finish Add" << endl;
        pool.WaitAll();
    }
}
                                    
                                    
                                    
                                
You are free to use my updated version which has all deadlocks fixed: https://github.com/stfx/ThreadPool2
@stfx Have you considered doing a pull request?
https://github.com/nbsdx/ThreadPool/pull/9
Somehow slipped past my view, thanks.