@@ -446,6 +446,7 @@ var LibraryPThread = {
446446 } ,
447447
448448 __emscripten_thread_cleanup : function ( thread ) {
449+ // Called when a thread needs to be cleaned up so it can be reused.
449450 if ( ! ENVIRONMENT_IS_PTHREAD ) cleanupThread ( thread ) ;
450451 else postMessage ( { 'cmd' : 'cleanupThread' , 'thread' : thread } ) ;
451452 } ,
@@ -788,12 +789,12 @@ var LibraryPThread = {
788789#endif
789790 } ,
790791
791- pthread_kill__deps : [ '$killThread' , ' emscripten_main_browser_thread_id'] ,
792+ pthread_kill__deps : [ 'emscripten_main_browser_thread_id' ] ,
792793 pthread_kill : function ( thread , signal ) {
793794 if ( signal < 0 || signal >= 65 /*_NSIG*/ ) return { { { cDefine ( 'EINVAL' ) } } } ;
794795 if ( thread === _emscripten_main_browser_thread_id ( ) ) {
795796 if ( signal == 0 ) return 0 ; // signal == 0 is a no-op.
796- err ( 'Main thread (id=' + thread + ') cannot be killed with pthread_kill!' ) ;
797+ err ( 'Main thread (id=0x ' + thread . toString ( 16 ) + ') cannot be killed with pthread_kill!' ) ;
797798 return { { { cDefine ( 'ESRCH' ) } } } ;
798799 }
799800 if ( ! thread ) {
@@ -802,38 +803,19 @@ var LibraryPThread = {
802803 }
803804 var self = { { { makeGetValue ( 'thread' , C_STRUCTS . pthread . self , 'i32' ) } } } ;
804805 if ( self !== thread ) {
805- err ( 'pthread_kill attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!' ) ;
806+ err ( 'pthread_kill attempted on thread 0x ' + thread . toString ( 16 ) + ', which does not point to a valid thread, or does not exist anymore!' ) ;
806807 return { { { cDefine ( 'ESRCH' ) } } } ;
807808 }
808- if ( signal != 0 ) {
809+ if ( signal === { { { cDefine ( 'SIGCANCEL' ) } } } ) { // Used by pthread_cancel in musl
810+ if ( ! ENVIRONMENT_IS_PTHREAD ) cancelThread ( thread ) ;
811+ else postMessage ( { 'cmd' : 'cancelThread' , 'thread' : thread } ) ;
812+ } else if ( signal != 0 ) {
809813 if ( ! ENVIRONMENT_IS_PTHREAD ) killThread ( thread ) ;
810- else postMessage ( { 'cmd' : 'killThread' , 'thread' : thread } ) ;
814+ else postMessage ( { 'cmd' : 'killThread' , 'thread' : thread } ) ;
811815 }
812816 return 0 ;
813817 } ,
814818
815- pthread_cancel__deps: [ '$cancelThread' , 'emscripten_main_browser_thread_id' ] ,
816- pthread_cancel : function ( thread ) {
817- if ( thread === _emscripten_main_browser_thread_id ( ) ) {
818- err ( 'Main thread (id=' + thread + ') cannot be canceled!' ) ;
819- return { { { cDefine ( 'ESRCH' ) } } } ;
820- }
821- if ( ! thread ) {
822- err ( 'pthread_cancel attempted on a null thread pointer!' ) ;
823- return { { { cDefine ( 'ESRCH' ) } } } ;
824- }
825- var self = { { { makeGetValue ( 'thread' , C_STRUCTS . pthread . self , 'i32' ) } } } ;
826- if ( self !== thread ) {
827- err ( 'pthread_cancel attempted on thread ' + thread + ', which does not point to a valid thread, or does not exist anymore!' ) ;
828- return { { { cDefine ( 'ESRCH' ) } } } ;
829- }
830- // Signal the thread that it needs to cancel itself.
831- Atomics . store ( HEAPU32 , ( thread + { { { C_STRUCTS . pthread . cancel } } } ) >> 2 , 1 ) ;
832- if ( ! ENVIRONMENT_IS_PTHREAD ) cancelThread ( thread ) ;
833- else postMessage ( { 'cmd' : 'cancelThread' , 'thread' : thread } ) ;
834- return 0 ;
835- } ,
836-
837819 __pthread_detached_exit: function ( ) {
838820 // Called at the end of pthread_exit (which occurs also when leaving the
839821 // thread main function) if an only if the thread is in a detached state.
0 commit comments