@@ -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
141140hx::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
147153Dynamic 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
0 commit comments