////////////////////////////////////////////////////////////////////// First half of termination process: stop thread manager, schedule a task managed by timer_pool to initiate second part
| 604 | // First half of termination process: stop thread manager, |
| 605 | // schedule a task managed by timer_pool to initiate second part |
| 606 | void runtime_distributed::stop(bool blocking) |
| 607 | { |
| 608 | LRT_(warning).format("runtime_distributed: about to stop services"); |
| 609 | |
| 610 | // flush all parcel buffers, stop buffering parcels at this point |
| 611 | //parcel_handler_.do_background_work(true, parcelport_background_mode::all); |
| 612 | |
| 613 | // execute all on_exit functions whenever the first thread calls this |
| 614 | this->runtime::stopping(); |
| 615 | |
| 616 | // stop runtime_distributed services (threads) |
| 617 | thread_manager_->stop(false); // just initiate shutdown |
| 618 | |
| 619 | #ifdef HPX_HAVE_APEX |
| 620 | util::external_timer::finalize(); |
| 621 | #endif |
| 622 | |
| 623 | if (threads::get_self_ptr()) |
| 624 | { |
| 625 | // schedule task on separate thread to execute stop_helper() below |
| 626 | // this is necessary as this function (stop()) might have been called |
| 627 | // from a HPX thread, so it would deadlock by waiting for the thread |
| 628 | // manager |
| 629 | std::mutex mtx; |
| 630 | std::condition_variable cond; |
| 631 | std::unique_lock<std::mutex> l(mtx); |
| 632 | |
| 633 | std::thread t(hpx::bind(&runtime_distributed::stop_helper, this, |
| 634 | blocking, std::ref(cond), std::ref(mtx))); |
| 635 | cond.wait(l); //-V1089 |
| 636 | |
| 637 | t.join(); |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | runtime_support_->stopped(); // re-activate shutdown HPX-thread |
| 642 | thread_manager_->stop(blocking); // wait for thread manager |
| 643 | |
| 644 | deinit_global_data(); |
| 645 | |
| 646 | // this disables all logging from the main thread |
| 647 | deinit_tss_helper("main-thread", 0); |
| 648 | |
| 649 | LRT_(info).format("runtime_distributed: stopped all services"); |
| 650 | } |
| 651 | |
| 652 | // stop the rest of the system |
| 653 | #if defined(HPX_HAVE_NETWORKING) |
| 654 | parcel_handler_.stop(blocking); |
| 655 | #endif |
| 656 | #ifdef HPX_HAVE_TIMER_POOL |
| 657 | LTM_(info).format("stop: stopping timer pool"); |
| 658 | timer_pool_->stop(); |
| 659 | if (blocking) |
| 660 | { |
| 661 | timer_pool_->join(); |
| 662 | timer_pool_->clear(); |
| 663 | } |
no test coverage detected