Merge pull request #1 from kimcinoo/taskqueues

taskscheduler: initialize member correctly
This commit is contained in:
Hermet Park 2020-08-24 17:40:15 +09:00 committed by GitHub
commit a9b587d930
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,11 +101,12 @@ class TaskSchedulerImpl
public: public:
unsigned threadCnt; unsigned threadCnt;
vector<thread> threads; vector<thread> threads;
vector<TaskQueue> taskQueues{threadCnt}; vector<TaskQueue> taskQueues;
atomic<unsigned> idx{0}; atomic<unsigned> idx{0};
TaskSchedulerImpl() TaskSchedulerImpl(unsigned count) : taskQueues(count)
{ {
threadCnt = count;
for (unsigned i = 0; i < threadCnt; ++i) { for (unsigned i = 0; i < threadCnt; ++i) {
threads.emplace_back([&, i] { run(i); }); threads.emplace_back([&, i] { run(i); });
} }
@ -168,8 +169,7 @@ static TaskSchedulerImpl* inst = nullptr;
void TaskScheduler::init(unsigned threads) void TaskScheduler::init(unsigned threads)
{ {
if (inst) return; if (inst) return;
inst = new TaskSchedulerImpl; inst = new TaskSchedulerImpl(threads);
inst->threadCnt = threads;
} }