@@ -285,11 +285,13 @@ var LibraryPThread = {
285
285
err ( 'Thread ' + d [ 'threadId' ] + ': ' + d [ 'text' ] ) ;
286
286
} else if ( cmd === 'alert' ) {
287
287
alert ( 'Thread ' + d [ 'threadId' ] + ': ' + d [ 'text' ] ) ;
288
- } else if ( cmd === 'exit' ) {
289
- var detached = worker . pthread && Atomics . load ( HEAPU32 , ( worker . pthread . threadInfoStruct + { { { C_STRUCTS . pthread . detached } } } ) >> 2 ) ;
290
- if ( detached ) {
291
- PThread . returnWorkerToPool ( worker ) ;
292
- }
288
+ } else if ( cmd === 'detachedExit' ) {
289
+ #if ASSERTIONS
290
+ assert ( worker . pthread ) ;
291
+ var detached = Atomics . load ( HEAPU32 , ( worker . pthread . threadInfoStruct + { { { C_STRUCTS . pthread . detached } } } ) >> 2 ) ;
292
+ assert ( detached ) ;
293
+ #endif
294
+ PThread . returnWorkerToPool ( worker ) ;
293
295
} else if ( cmd === 'exitProcess' ) {
294
296
// A pthread has requested to exit the whole application process (runtime).
295
297
#if ASSERTIONS
@@ -331,7 +333,7 @@ var LibraryPThread = {
331
333
worker . on ( 'error' , function ( e ) {
332
334
worker . onerror ( e ) ;
333
335
} ) ;
334
- worker . on ( 'exit ' , function ( ) {
336
+ worker . on ( 'detachedExit ' , function ( ) {
335
337
// TODO: update the worker queue?
336
338
// See: https://github.com/emscripten-core/emscripten/issues/9763
337
339
} ) ;
@@ -901,29 +903,14 @@ var LibraryPThread = {
901
903
return 0 ;
902
904
} ,
903
905
904
- __pthread_detach_js__sig : 'vi' ,
905
- __pthread_detach_js : function ( thread ) {
906
- if ( ! thread ) {
907
- err ( 'pthread_detach attempted on a null thread pointer!' ) ;
908
- return { { { cDefine ( 'ESRCH' ) } } } ;
909
- }
910
- var self = { { { makeGetValue ( 'thread' , C_STRUCTS . pthread . self , 'i32' ) } } } ;
911
- if ( self !== thread ) {
912
- err ( 'pthread_detach attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!' ) ;
913
- return { { { cDefine ( 'ESRCH' ) } } } ;
914
- }
915
- // Follow musl convention: detached:0 means not detached, 1 means the thread
916
- // was created as detached, and 2 means that the thread was detached via
917
- // pthread_detach.
918
- var wasDetached = Atomics . compareExchange ( HEAPU32 , ( thread + { { { C_STRUCTS . pthread . detached } } } ) >> 2 , 0 , 2 ) ;
919
-
920
- return wasDetached ? { { { cDefine ( 'EINVAL' ) } } } : 0 ;
921
- } ,
922
-
923
906
__pthread_exit_run_handlers__deps : [ 'exit' ] ,
924
907
__pthread_exit_run_handlers : function ( status ) {
925
908
// Called from pthread_exit, either when called explicitly called
926
909
// by programmer, or implicitly when leaving the thread main function.
910
+ //
911
+ // Note: in theory we would like to return any offscreen canvases back to
912
+ // the main thread, but if we ever fetched a rendering context for them that
913
+ // would not be valid, so we don't try.
927
914
928
915
#if PTHREADS_DEBUG
929
916
var tb = _pthread_self ( ) ;
@@ -936,13 +923,10 @@ var LibraryPThread = {
936
923
}
937
924
} ,
938
925
939
- __pthread_exit_done : function ( ) {
940
- // Called at the end of pthread_exit, either when called explicitly called
941
- // by programmer, or implicitly when leaving the thread main function.
942
- //
943
- // Note: in theory we would like to return any offscreen canvases back to the main thread,
944
- // but if we ever fetched a rendering context for them that would not be valid, so we don't try.
945
- postMessage ( { 'cmd' : 'exit' } ) ;
926
+ __pthread_detached_exit : function ( ) {
927
+ // Called at the end of pthread_exit (which occurs also when leaving the
928
+ // thread main function) if an only if the thread is in a detached state.
929
+ postMessage ( { 'cmd' : 'detachedExit' } ) ;
946
930
} ,
947
931
948
932
__cxa_thread_atexit__sig : 'vii ',
0 commit comments