| 280 | } |
| 281 | |
| 282 | bool team_destroy(void) |
| 283 | { int rc; |
| 284 | |
| 285 | // Current state is other threads are at wait_for_job_. |
| 286 | // This master thread (thread zero) has not completed wait_for_job_ |
| 287 | bool ok = sequential_execution_; |
| 288 | ok &= thread_number() == 0; |
| 289 | |
| 290 | // set the new job that other threads are waiting for |
| 291 | thread_job_ = join_enum; |
| 292 | |
| 293 | // Enter parallel execution soon as master thread completes wait_for_job_ |
| 294 | if( num_threads_ > 1 ) |
| 295 | sequential_execution_ = false; |
| 296 | rc = pthread_barrier_wait(&wait_for_job_); |
| 297 | ok &= (rc == 0 || rc == PTHREAD_BARRIER_SERIAL_THREAD); |
| 298 | |
| 299 | // now wait for the other threads to exit |
| 300 | size_t thread_num; |
| 301 | for(thread_num = 1; thread_num < num_threads_; thread_num++) |
| 302 | { void* no_status = nullptr; |
| 303 | rc = pthread_join( |
| 304 | thread_all_[thread_num].pthread_id, &no_status |
| 305 | ); |
| 306 | ok &= (rc == 0); |
| 307 | } |
| 308 | |
| 309 | // now we are down to just the master thread (thread zero) |
| 310 | sequential_execution_ = true; |
| 311 | |
| 312 | // destroy the key for thread specific data |
| 313 | pthread_key_delete(thread_specific_key_); |
| 314 | |
| 315 | // destroy wait_for_work_ |
| 316 | rc = pthread_barrier_destroy(&wait_for_work_); |
| 317 | ok &= (rc == 0); |
| 318 | |
| 319 | // destroy wait_for_job_ |
| 320 | rc = pthread_barrier_destroy(&wait_for_job_); |
| 321 | ok &= (rc == 0); |
| 322 | |
| 323 | // check ok before changing num_threads_ |
| 324 | for(thread_num = 0; thread_num < num_threads_; thread_num++) |
| 325 | ok &= thread_all_[thread_num].ok; |
| 326 | |
| 327 | // now inform CppAD that there is only one thread |
| 328 | num_threads_ = 1; |
| 329 | thread_alloc::parallel_setup(num_threads_, nullptr, nullptr); |
| 330 | thread_alloc::hold_memory(false); |
| 331 | CppAD::parallel_ad<double>(); |
| 332 | |
| 333 | return ok; |
| 334 | } |
| 335 | |
| 336 | const char* team_name(void) |
| 337 | { return "pthread"; } |
nothing calls this directly
no test coverage detected