Skip to content

Commit 2d5dd14

Browse files
authored
Merge pull request STEllAR-GROUP#6701 from STEllAR-GROUP/fixing_6699
Attempting to fix shutdown hang on exception_info
2 parents 24621cb + d53e57e commit 2d5dd14

File tree

11 files changed

+155
-63
lines changed

11 files changed

+155
-63
lines changed

libs/core/resource_partitioner/src/detail_partitioner.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
namespace hpx::resource::detail {
3636

3737
///////////////////////////////////////////////////////////////////////////
38-
[[noreturn]] void throw_runtime_error(
38+
[[noreturn]] static void throw_runtime_error(
3939
std::string const& func, std::string const& message)
4040
{
4141
HPX_THROW_EXCEPTION(hpx::error::invalid_status, func, message);
4242
}
4343

44-
[[noreturn]] void throw_invalid_argument(
44+
[[noreturn]] static void throw_invalid_argument(
4545
std::string const& func, std::string const& message)
4646
{
4747
HPX_THROW_EXCEPTION(hpx::error::bad_parameter, func, message);
@@ -1008,9 +1008,12 @@ namespace hpx::resource::detail {
10081008
void partitioner::unassign_pu(
10091009
std::string const& pool_name, std::size_t virt_core)
10101010
{
1011-
std::unique_lock<mutex_type> l(mtx_);
1012-
detail::init_pool_data& data = get_pool_data(l, pool_name);
1013-
data.unassign_pu(virt_core);
1011+
std::unique_lock<mutex_type> l(mtx_, std::defer_lock);
1012+
if (l.try_lock())
1013+
{
1014+
detail::init_pool_data& data = get_pool_data(l, pool_name);
1015+
data.unassign_pu(virt_core);
1016+
}
10141017
}
10151018

10161019
std::size_t partitioner::shrink_pool(std::string const& pool_name,
@@ -1185,7 +1188,7 @@ namespace hpx::resource::detail {
11851188
<< static_cast<std::uint64_t>(initial_thread_pools_.size())
11861189
<< " pool(s) : \n"; // -V128
11871190

1188-
for (auto itp : initial_thread_pools_)
1191+
for (auto const& itp : initial_thread_pools_)
11891192
{
11901193
itp.print_pool(os);
11911194
}

libs/core/runtime_local/include/hpx/runtime_local/custom_exception_info.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2024 Hartmut Kaiser
1+
// Copyright (c) 2007-2025 Hartmut Kaiser
22
// Copyright (c) 2011 Bryce Lelbach
33
//
44
// SPDX-License-Identifier: BSL-1.0
@@ -159,12 +159,27 @@ namespace hpx {
159159
HPX_CORE_EXPORT std::string diagnostic_information(
160160
exception_info const& xi);
161161

162+
HPX_CORE_EXPORT std::string default_diagnostic_information(
163+
std::exception_ptr const& e);
164+
162165
/// \cond NOINTERNAL
163166
template <typename E>
164167
std::string diagnostic_information(E const& e)
165168
{
166-
return invoke_with_exception_info(e, [](exception_info const* xi) {
167-
return xi ? diagnostic_information(*xi) : std::string("<unknown>");
169+
return invoke_with_exception_info(e, [&](exception_info const* xi) {
170+
if (xi)
171+
{
172+
return diagnostic_information(*xi);
173+
}
174+
175+
if constexpr (std::is_same_v<std::exception_ptr, E>)
176+
{
177+
return default_diagnostic_information(e);
178+
}
179+
else
180+
{
181+
return std::string("<unknown>");
182+
}
168183
});
169184
}
170185
/// \endcond

libs/core/runtime_local/src/custom_exception_info.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2016 Hartmut Kaiser
1+
// Copyright (c) 2007-2025 Hartmut Kaiser
22
// Copyright (c) 2011 Bryce Lelbach
33
//
44
// SPDX-License-Identifier: BSL-1.0
@@ -66,6 +66,20 @@ namespace hpx {
6666
///////////////////////////////////////////////////////////////////////////
6767
// Extract the diagnostic information embedded in the given exception and
6868
// return a string holding a formatted message.
69+
std::string default_diagnostic_information(std::exception_ptr const& e)
70+
{
71+
try
72+
{
73+
if (e)
74+
std::rethrow_exception(e);
75+
}
76+
catch (std::exception const& ex)
77+
{
78+
return {ex.what()};
79+
}
80+
return {"<unknown>"};
81+
}
82+
6983
std::string diagnostic_information(hpx::exception_info const& xi)
7084
{
7185
int const verbosity = util::from_string<int>(
@@ -173,7 +187,7 @@ namespace hpx::util {
173187

174188
// This is a local helper used to get the backtrace on a new stack if
175189
// possible.
176-
std::string trace_on_new_stack(
190+
static std::string trace_on_new_stack(
177191
std::size_t frames_no = HPX_HAVE_THREAD_BACKTRACE_DEPTH)
178192
{
179193
#if defined(HPX_HAVE_STACKTRACES)
@@ -342,7 +356,7 @@ namespace hpx::detail {
342356

343357
///////////////////////////////////////////////////////////////////////////
344358
// Figure out the size of the given environment
345-
inline std::size_t get_arraylen(char** array)
359+
static std::size_t get_arraylen(char** array)
346360
{
347361
std::size_t count = 0;
348362
if (nullptr != array)

libs/core/runtime_local/src/runtime_local.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ namespace hpx {
630630
void runtime::deinit_global_data()
631631
{
632632
runtime*& runtime_ = get_runtime_ptr();
633-
HPX_ASSERT(runtime_);
634633
runtime_uptime() = 0;
635634
runtime_ = nullptr;
636635
}

libs/core/thread_pools/include/hpx/thread_pools/scheduled_thread_pool_impl.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ namespace hpx::threads::detail {
109109
std::unique_lock<std::mutex> l(mtx);
110110
stop_locked(l);
111111
}
112+
113+
// avoid problems during fatal exceptions handling
114+
for (auto& t : threads_)
115+
{
116+
if (t.joinable())
117+
t.join();
118+
}
112119
threads_.clear();
113120
}
114121
}
@@ -366,16 +373,20 @@ namespace hpx::threads::detail {
366373
void scheduled_thread_pool<Scheduler>::resume_internal(
367374
bool blocking, error_code& ec)
368375
{
376+
// clang-format off
369377
for (std::size_t virt_core = 0; virt_core != threads_.size();
370-
++virt_core)
378+
++virt_core)
379+
// clang-format on
371380
{
372381
this->sched_->Scheduler::resume(virt_core);
373382
}
374383

375384
if (blocking)
376385
{
386+
// clang-format off
377387
for (std::size_t virt_core = 0; virt_core != threads_.size();
378-
++virt_core)
388+
++virt_core)
389+
// clang-format on
379390
{
380391
if (threads_[virt_core].joinable())
381392
{

libs/core/threadmanager/include/hpx/modules/threadmanager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace hpx::threads {
5858
util::io_service_pool& timer_pool,
5959
#endif
6060
notification_policy_type& notifier,
61-
detail::network_background_callback_type const&
61+
detail::network_background_callback_type
6262
network_background_callback =
6363
detail::network_background_callback_type());
6464

0 commit comments

Comments
 (0)