MCPcopy Create free account
hub / github.com/chen3feng/toft / ThreadPool

Method ThreadPool

system/threading/thread_pool.cpp:54–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54ThreadPool::ThreadPool(int num_threads):
55 m_num_threads(0), m_num_busy_threads(0), m_exit_cond(&m_exit_lock), m_exit(false) {
56 if (num_threads < 0)
57 m_num_threads = GetLogicalCpuNumber();
58 else if (num_threads == 0)
59 m_num_threads = 1;
60 else
61 m_num_threads = num_threads;
62
63 m_thread_contexts = new ThreadContext[m_num_threads];
64 ThreadAttributes attr;
65 for (size_t i = 0; i < m_num_threads; ++i) {
66 attr.SetName(StringConcat("threadpool/", i));
67 m_thread_contexts[i].thread.reset(
68 new Thread(attr, std::bind(&ThreadPool::WorkRoutine, this, &m_thread_contexts[i])));
69 }
70 m_num_busy_threads = m_num_threads;
71}
72
73
74ThreadPool::~ThreadPool() {

Callers

nothing calls this directly

Calls 3

GetLogicalCpuNumberFunction · 0.85
StringConcatFunction · 0.85
resetMethod · 0.45

Tested by

no test coverage detected