Skip to content

Commit aac3f9a

Browse files
author
Aidan Lee
committed
Bodge it
1 parent 3c5ae67 commit aac3f9a

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/hx/thread/ThreadImpl.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ hx::thread::Thread hx::thread::Thread_obj::create(CreateFunction job)
7171

7272
auto semaphore = new hx::thread::CountingSemaphore_obj(0);
7373
auto obj = new ThreadImpl_obj(nextThreadnumber++, job, semaphore);
74-
//auto native = new ThreadImpl_obj::Native(new std::thread(run, obj, job, semaphore));
7574

7675
hx::GCSetFinalizer(obj, ThreadImpl_obj::finalise);
7776
hx::GCPrepareMultiThreaded();
@@ -139,9 +138,16 @@ hx::thread::ThreadImpl_obj::ThreadImpl_obj(const int _id, Thread_obj::CreateFunc
139138
}
140139

141140
hx::thread::ThreadImpl_obj::Native::Native(Thread_obj::CreateFunction _job, ThreadImpl _thread, CountingSemaphore _semaphore)
142-
: thread(new std::thread(run, _thread, _job, _semaphore))
143-
, handle(thread->native_handle())
141+
: thread(run, _thread, _job, _semaphore)
142+
, handle(thread.native_handle())
144143
{
144+
// Only Windows implements thread name getting and setting currently, and this requires the thread to be attached.
145+
// Threads are normally only detached once the thread object is finalised and this was causing the 32bit linux tests to hit OS resource limits.
146+
// This does feel like a bit of a bodge and something which will actually need to be addressed to add name setting on Linux.
147+
148+
#ifndef HX_WINDOWS
149+
thread.detach();
150+
#endif
145151
}
146152

147153
Dynamic hx::thread::ThreadImpl_obj::getSlot(const int id)
@@ -173,9 +179,9 @@ void hx::thread::ThreadImpl_obj::finalise(hx::Object* obj)
173179
auto thread = reinterpret_cast<ThreadImpl_obj*>(obj);
174180
auto native = std::unique_ptr<ThreadImpl_obj::Native>{ thread->native };
175181

176-
if (native->thread)
182+
if (native->thread.joinable())
177183
{
178-
native->thread->detach();
184+
native->thread.detach();
179185
}
180186
}
181187

src/hx/thread/ThreadImpl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace hx
2626

2727
struct Native
2828
{
29-
std::unique_ptr<std::thread> thread;
29+
std::thread thread;
3030
std::thread::native_handle_type handle;
3131

3232
Native();

0 commit comments

Comments
 (0)