Skip to content

Commit a1ce77b

Browse files
committed
Call abort() for Stop when thread id differs from main thread id
1 parent 182d32f commit a1ce77b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

flang-rt/lib/runtime/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <cfenv>
1313
#include <cstdio>
1414
#include <cstdlib>
15+
#include <thread>
16+
std::thread::id main_thread_id = std::this_thread::get_id();
17+
extern "C" std::thread::id get_main_thread_id() { return main_thread_id; }
1518

1619
static void ConfigureFloatingPoint() {
1720
#ifdef feclearexcept // a macro in some environments; omit std::

flang-rt/lib/runtime/stop.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <cfenv>
1717
#include <cstdio>
1818
#include <cstdlib>
19+
#include <thread>
20+
std::thread::id get_main_thread_id();
1921

2022
#ifdef HAVE_BACKTRACE
2123
#include BACKTRACE_HEADER
@@ -79,6 +81,8 @@ static void CloseAllExternalUnits(const char *why) {
7981
std::fputc('\n', stderr);
8082
DescribeIEEESignaledExceptions();
8183
}
84+
if (get_main_thread_id() != std::this_thread::get_id())
85+
std::abort();
8286
std::exit(code);
8387
}
8488

@@ -94,6 +98,8 @@ static void CloseAllExternalUnits(const char *why) {
9498
}
9599
DescribeIEEESignaledExceptions();
96100
}
101+
if (get_main_thread_id() != std::this_thread::get_id())
102+
std::abort();
97103
if (isErrorStop) {
98104
std::exit(EXIT_FAILURE);
99105
} else {

0 commit comments

Comments
 (0)