ThreadPool icon indicating copy to clipboard operation
ThreadPool copied to clipboard

Dead-Lock

Open CheYulin opened this issue 9 years ago • 4 comments

  • 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();
    }
}

CheYulin avatar Sep 12 '16 11:09 CheYulin

You are free to use my updated version which has all deadlocks fixed: https://github.com/stfx/ThreadPool2

DomGries avatar Nov 18 '16 13:11 DomGries

@stfx Have you considered doing a pull request?

devnoname120 avatar Aug 01 '17 22:08 devnoname120

https://github.com/nbsdx/ThreadPool/pull/9

DomGries avatar Aug 02 '17 05:08 DomGries

Somehow slipped past my view, thanks.

devnoname120 avatar Aug 02 '17 07:08 devnoname120