Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Dead-Lock #12

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions