Skip to content

Commit a3ec35c

Browse files
committed
Use ::_exit when multi-threaded not in main thread
Signed-off-by: Bartłomiej Chmiel <bchmiel@antmicro.com>
1 parent 4bc83a2 commit a3ec35c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/V3Error.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# include "V3Stats.h"
2424
VL_DEFINE_DEBUG_FUNCTIONS;
2525
#endif
26+
#include <thread>
2627
// clang-format on
2728

2829
//======================================================================
@@ -88,11 +89,20 @@ void V3ErrorGuarded::vlAbortOrExit() VL_REQUIRES(m_mutex) {
8889
if (V3Error::debugDefault()) {
8990
std::cerr << msgPrefix() << "Aborting since under --debug" << endl;
9091
V3Error::vlAbort();
91-
} else {
92+
}
93+
#ifndef V3ERROR_NO_GLOBAL_
94+
else if (v3Global.opt.verilateJobs() > 1
95+
&& v3Global.mainThreadId() != std::this_thread::get_id()) {
96+
VL_GCOV_DUMP(); // No static destructors are called, thus must be called manually.
97+
9298
// Exit without triggering any global destructors.
9399
// Used to prevent detached V3ThreadPool jobs accessing destroyed static objects.
94100
::_exit(1);
95101
}
102+
#endif
103+
else {
104+
std::exit(1);
105+
}
96106
}
97107

98108
string V3ErrorGuarded::warnMore() VL_REQUIRES(m_mutex) { return string(msgPrefix().size(), ' '); }

src/V3Global.h

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "V3Options.h"
3333

3434
#include <string>
35+
#include <thread>
3536
#include <unordered_map>
3637
#include <unordered_set>
3738

@@ -133,6 +134,9 @@ class V3Global final {
133134
// Names of fields that were dumped by dumpJsonPtr()
134135
std::unordered_set<std::string> m_jsonPtrNames;
135136

137+
// Id of the main thread
138+
const std::thread::id m_mainThreadId = std::this_thread::get_id();
139+
136140
public:
137141
// Options
138142
V3Options opt; // All options; let user see them directly
@@ -203,6 +207,7 @@ class V3Global final {
203207
void ptrNamesDumpJson(std::ostream& os);
204208
void idPtrMapDumpJson(std::ostream& os);
205209
const std::string& ptrToId(const void* p);
210+
std::thread::id mainThreadId() const { return m_mainThreadId; }
206211
};
207212

208213
extern V3Global v3Global;

0 commit comments

Comments
 (0)