MCPcopy Create free account
hub / github.com/EricPengShuai/Interview / startPool

Method startPool

practice/threadpool.cpp:36–50  ·  view source on GitHub ↗

开启线程池

Source from the content-addressed store, hash-verified

34
35 // 开启线程池
36 void startPool(int size)
37 {
38 for (int i = 0; i < size; ++ i) {
39 // Thread 参数是一个函数对象,可以使用 bind 绑定
40 _pool.push_back(new Thread(bind(&ThreadPool::runInThread, this, std::placeholders::_1), i));
41 }
42
43 for (int i = 0; i < size; ++ i) {
44 _handler.push_back(_pool[i]->start());
45 }
46
47 for (thread &t: _handler) {
48 t.join();
49 }
50 }
51private:
52 vector<Thread *> _pool;
53 vector<thread> _handler;

Callers 1

mainFunction · 0.80

Calls 2

startMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected