MCPcopy Create free account
hub / github.com/coin-or/CppAD / team_work

Function team_work

example/multi_thread/bthread/team_bthread.cpp:173–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173bool team_work(void worker(void))
174{
175 // Current state is other threads are at wait_for_job_.
176 // This master thread (thread zero) has not completed wait_for_job_
177 bool ok = sequential_execution_;
178 ok &= thread_number() == 0;
179 ok &= wait_for_work_ != nullptr;
180 ok &= wait_for_job_ != nullptr;
181
182 // set global version of this work routine
183 worker_ = worker;
184
185 // set the new job that other threads are waiting for
186 thread_job_ = work_enum;
187
188 // Enter parallel execution when master thread calls wait_for_job_
189 if( num_threads_ > 1 )
190 sequential_execution_ = false;
191 wait_for_job_->wait();
192
193 // Now do the work in this thread and then wait
194 // until all threads have completed wait_for_work_
195 worker();
196 wait_for_work_->wait();
197
198 // Current state is other threads are at wait_for_job_.
199 // This master thread (thread zero) has not completed wait_for_job_
200 sequential_execution_ = true;
201
202 size_t thread_num;
203 for(thread_num = 0; thread_num < num_threads_; thread_num++)
204 ok &= thread_all_[thread_num].ok;
205 return ok;
206}
207
208bool team_destroy(void)
209{ // Current state is other threads are at wait_for_job_.

Callers

nothing calls this directly

Calls 2

thread_numberFunction · 0.70
workerFunction · 0.50

Tested by

no test coverage detected