-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6321: Ensure hpx_main is a proper thread_function r=hkaiser a=Pansysk75 Ensure that hpx_main is launched as a thread_function, so that exit callbacks are respected, and the following code will actually be used: https://github.com/STEllAR-GROUP/hpx/blob/e7c31a49dd4e550a61134e498f3ecfb585d201cb/libs/core/threading_base/include/hpx/threading_base/register_thread.hpp#L28-L52 I should add that previously the callbacks were never executed, so using add_thread_exit_callback would cause an assertion failure later on thread destruction (L163), due to this sequence of calls: https://github.com/STEllAR-GROUP/hpx/blob/e7c31a49dd4e550a61134e498f3ecfb585d201cb/libs/core/threading_base/src/thread_data.cpp#L107-L111 https://github.com/STEllAR-GROUP/hpx/blob/e7c31a49dd4e550a61134e498f3ecfb585d201cb/libs/core/threading_base/src/thread_data.cpp#L157-L166 `@hkaiser` Let me know if this is a good idea, and whether you'd like me to add a regression test. Co-authored-by: Panos <pansysk75@gmail.com> Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
- Loading branch information
Showing
5 changed files
with
107 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2023 Panos Syskakis | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <hpx/init.hpp> | ||
#include <hpx/modules/testing.hpp> | ||
#include <hpx/runtime.hpp> | ||
#include <hpx/thread.hpp> | ||
|
||
#include <atomic> | ||
#include <cstddef> | ||
|
||
bool callback_called(false); | ||
|
||
int hpx_main() | ||
{ | ||
hpx::threads::thread_id_type id = hpx::threads::get_self_id(); | ||
hpx::threads::add_thread_exit_callback(id, [id]() { | ||
hpx::threads::thread_id_type id1 = hpx::threads::get_self_id(); | ||
HPX_TEST_EQ(id1, id); | ||
|
||
callback_called = true; | ||
}); | ||
|
||
return hpx::finalize(); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
// Test local runtime | ||
{ | ||
hpx::init_params iparams; | ||
iparams.mode = hpx::runtime_mode::local; | ||
callback_called = false; | ||
HPX_TEST_EQ_MSG(hpx::init(argc, argv, iparams), 0, | ||
"HPX main exited with non-zero status"); | ||
HPX_TEST(callback_called); | ||
} | ||
|
||
#if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) | ||
// Test distributed runtime | ||
{ | ||
hpx::init_params iparams; | ||
iparams.mode = hpx::runtime_mode::console; | ||
callback_called = false; | ||
HPX_TEST_EQ_MSG(hpx::init(argc, argv, iparams), 0, | ||
"HPX main exited with non-zero status"); | ||
|
||
HPX_TEST(callback_called); | ||
} | ||
#endif | ||
return hpx::util::report_errors(); | ||
} |