| 206 | } |
| 207 | |
| 208 | bool team_destroy(void) |
| 209 | { // Current state is other threads are at wait_for_job_. |
| 210 | // This master thread (thread zero) has not completed wait_for_job_ |
| 211 | bool ok = sequential_execution_; |
| 212 | ok &= thread_number() == 0; |
| 213 | ok &= wait_for_work_ != nullptr; |
| 214 | ok &= wait_for_job_ != nullptr; |
| 215 | |
| 216 | // set the new job that other threads are waiting for |
| 217 | thread_job_ = join_enum; |
| 218 | |
| 219 | // enter parallel execution soon as master thread completes wait_for_job_ |
| 220 | if( num_threads_ > 1 ) |
| 221 | sequential_execution_ = false; |
| 222 | wait_for_job_->wait(); |
| 223 | |
| 224 | // now wait for the other threads to be destroyed |
| 225 | size_t thread_num; |
| 226 | ok &= thread_all_[0].bthread == nullptr; |
| 227 | for(thread_num = 1; thread_num < num_threads_; thread_num++) |
| 228 | { thread_all_[thread_num].bthread->join(); |
| 229 | delete thread_all_[thread_num].bthread; |
| 230 | thread_all_[thread_num].bthread = nullptr; |
| 231 | } |
| 232 | // now we are down to just the master thread (thread zero) |
| 233 | sequential_execution_ = true; |
| 234 | |
| 235 | // destroy wait_for_work_ |
| 236 | delete wait_for_work_; |
| 237 | wait_for_work_ = nullptr; |
| 238 | |
| 239 | // destroy wait_for_job_ |
| 240 | delete wait_for_job_; |
| 241 | wait_for_job_ = nullptr; |
| 242 | |
| 243 | // check ok before changing num_threads_ |
| 244 | for(thread_num = 0; thread_num < num_threads_; thread_num++) |
| 245 | ok &= thread_all_[thread_num].ok; |
| 246 | |
| 247 | // now inform CppAD that there is only one thread |
| 248 | num_threads_ = 1; |
| 249 | thread_alloc::parallel_setup(num_threads_, nullptr, nullptr); |
| 250 | thread_alloc::hold_memory(false); |
| 251 | CppAD::parallel_ad<double>(); |
| 252 | |
| 253 | return ok; |
| 254 | } |
| 255 | |
| 256 | const char* team_name(void) |
| 257 | { return "bthread"; } |
nothing calls this directly
no test coverage detected