Skip to content

Commit 7ecc590

Browse files
committed
Fix destruction of thread_local variable in MinGW
1 parent fca5e4f commit 7ecc590

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/tvision/internal/winwidth.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class WinWidth
2222

2323
static std::atomic<size_t> lastReset;
2424
static std::atomic<bool> isLegacyConsole;
25-
static thread_local WinWidth localInstance;
25+
static thread_local WinWidth &localInstance;
2626

2727
std::unordered_map<uint32_t, short> results;
2828
HANDLE cnHandle {INVALID_HANDLE_VALUE};
@@ -33,6 +33,7 @@ class WinWidth
3333
void tearDown() noexcept;
3434

3535
~WinWidth();
36+
struct Destructor;
3637

3738
public:
3839

source/platform/winwidth.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ namespace tvision
88

99
std::atomic<size_t> WinWidth::lastReset {0};
1010
std::atomic<bool> WinWidth::isLegacyConsole {false};
11-
WinWidth thread_local WinWidth::localInstance;
11+
WinWidth thread_local &WinWidth::localInstance = *new WinWidth;
12+
13+
// MinGW: work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562
14+
// by deleting 'localInstance' through a static reference.
15+
struct WinWidth::Destructor
16+
{
17+
~Destructor()
18+
{
19+
delete &localInstance;
20+
}
21+
} static thread_local destructor;
1222

1323
WinWidth::~WinWidth()
1424
{

0 commit comments

Comments
 (0)