@@ -1875,46 +1875,57 @@ void application_impl::shutdown() {
1875
1875
is_dispatching_ = false ;
1876
1876
dispatcher_condition_.notify_all ();
1877
1877
}
1878
- {
1879
- std::lock_guard<std::mutex> its_lock (dispatcher_mutex_);
1880
- for (auto its_dispatcher : dispatchers_) {
1881
- if (its_dispatcher.second ->get_id () != stop_caller_id_) {
1882
- if (its_dispatcher.second ->joinable ()) {
1883
- its_dispatcher.second ->join ();
1878
+
1879
+ try {
1880
+
1881
+ {
1882
+ std::lock_guard<std::mutex> its_lock (dispatcher_mutex_);
1883
+ for (auto its_dispatcher : dispatchers_) {
1884
+ if (its_dispatcher.second ->get_id () != stop_caller_id_) {
1885
+ if (its_dispatcher.second ->joinable ()) {
1886
+ its_dispatcher.second ->join ();
1887
+ }
1888
+ } else {
1889
+ // If the caller of stop() is one of our dispatchers
1890
+ // it can happen the shutdown mechanism will block
1891
+ // as that thread probably can't be joined. The reason
1892
+ // is the caller of stop() probably wants to join the
1893
+ // thread once call start (which got to the IO-Thread)
1894
+ // and which is expected to return after stop() has been
1895
+ // called.
1896
+ // Therefore detach this thread instead of joining because
1897
+ // after it will return to "main_dispatch" it will be
1898
+ // properly shutdown anyways because "is_dispatching_"
1899
+ // was set to "false" here.
1900
+ its_dispatcher.second ->detach ();
1884
1901
}
1885
- } else {
1886
- // If the caller of stop() is one of our dispatchers
1887
- // it can happen the shutdown mechanism will block
1888
- // as that thread probably can't be joined. The reason
1889
- // is the caller of stop() probably wants to join the
1890
- // thread once call start (which got to the IO-Thread)
1891
- // and which is expected to return after stop() has been
1892
- // called.
1893
- // Therefore detach this thread instead of joining because
1894
- // after it will return to "main_dispatch" it will be
1895
- // properly shutdown anyways because "is_dispatching_"
1896
- // was set to "false" here.
1897
- its_dispatcher.second ->detach ();
1898
1902
}
1903
+ availability_handlers_.clear ();
1904
+ running_dispatchers_.clear ();
1905
+ elapsed_dispatchers_.clear ();
1906
+ dispatchers_.clear ();
1899
1907
}
1900
- availability_handlers_.clear ();
1901
- running_dispatchers_.clear ();
1902
- elapsed_dispatchers_.clear ();
1903
- dispatchers_.clear ();
1904
- }
1905
1908
1906
- if (routing_)
1907
- routing_->stop ();
1909
+ if (routing_)
1910
+ routing_->stop ();
1908
1911
1909
- work_.reset ();
1910
- io_.stop ();
1912
+ work_.reset ();
1913
+ io_.stop ();
1911
1914
1912
- {
1913
- std::lock_guard<std::mutex> its_lock_start_stop (start_stop_mutex_);
1914
- for (auto t : io_threads_) {
1915
- t->join ();
1915
+ {
1916
+ std::lock_guard<std::mutex> its_lock_start_stop (start_stop_mutex_);
1917
+ for (auto t : io_threads_) {
1918
+ t->join ();
1919
+ }
1920
+ io_threads_.clear ();
1916
1921
}
1917
- io_threads_.clear ();
1922
+ #ifndef _WIN32
1923
+ } catch (const boost::log ::v2_mt_posix::system_error &e) {
1924
+ std::cerr << " catched boost::log system_error in stop thread" << std::endl <<
1925
+ boost::current_exception_diagnostic_information ();
1926
+ #endif
1927
+ } catch (const std::exception &e) {
1928
+ VSOMEIP_ERROR << " application_impl::shutdown() catched exception: " << e.what ();
1918
1929
}
1919
1930
}
1920
1931
0 commit comments