Skip to content

Commit c8bb97f

Browse files
ncannasseRandomityGuy
authored andcommitted
fixed bug with thread creation mutex (close HaxeFoundation#586)
1 parent 3788d3d commit c8bb97f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/std/thread.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ typedef struct {
827827
static void gc_thread_entry( thread_start *_s ) {
828828
thread_start s = *_s;
829829
hl_register_thread(&s);
830-
hl_lock_release(s.wait);
831-
s.wait = NULL;
830+
hl_lock_release(_s->wait);
831+
s.wait = _s->wait = NULL;
832832
_s = NULL;
833833
s.callb(s.param);
834834
hl_unregister_thread();
@@ -855,8 +855,10 @@ HL_PRIM hl_thread *hl_thread_start( void *callback, void *param, bool withGC ) {
855855
if( h == NULL )
856856
return NULL;
857857
CloseHandle(h);
858-
if( withGC )
859-
hl_lock_wait(((thread_start*)param)->wait, NULL);
858+
if( withGC ) {
859+
hl_lock *l = ((thread_start*)param)->wait;
860+
if( l ) hl_lock_wait(l, NULL);
861+
}
860862
return (hl_thread*)(int_val)tid;
861863
#else
862864
pthread_t t;
@@ -868,8 +870,10 @@ HL_PRIM hl_thread *hl_thread_start( void *callback, void *param, bool withGC ) {
868870
return NULL;
869871
}
870872
pthread_attr_destroy(&attr);
871-
if( withGC )
872-
hl_lock_wait(((thread_start*)param)->wait, NULL);
873+
if( withGC ) {
874+
hl_lock *l = ((thread_start*)param)->wait;
875+
if( l ) hl_lock_wait(l, NULL);
876+
}
873877
return (hl_thread*)t;
874878
#endif
875879
}

0 commit comments

Comments
 (0)