@@ -280,6 +280,8 @@ var LibraryPThread = {
280
280
assert ( worker . pthread ) ;
281
281
#endif
282
282
PThread . returnWorkerToPool ( worker ) ;
283
+ } else if ( cmd === 'cancelDone' ) {
284
+ PThread . returnWorkerToPool ( worker ) ;
283
285
} else if ( d . target === 'setimmediate' ) {
284
286
// Worker wants to postMessage() to itself to implement setImmediate()
285
287
// emulation.
@@ -458,17 +460,19 @@ var LibraryPThread = {
458
460
#endif
459
461
var pthread = PThread . pthreads [ pthread_ptr ] ;
460
462
// If pthread has been removed from this map this also means that pthread_ptr points
461
- // to already freed data. Such situation may occur in following circumstance:
462
- // Joining thread from non-main browser thread (this also includes thread running main()
463
- // when compiled with `PROXY_TO_PTHREAD`) - in such situation it may happen that following
464
- // code flow occur (MB - Main Browser Thread, S1, S2 - Worker Threads):
465
- // S2: thread ends, 'exit' message is sent to MB
466
- // S1: calls pthread_join(S2), this causes:
467
- // a. S2 is marked as detached,
468
- // b. 'cleanupThread' message is sent to MB.
469
- // MB: handles 'exit' message, as thread is detached, so returnWorkerToPool()
470
- // is called and all thread related structs are freed/released.
471
- // MB: handles 'cleanupThread' message which calls this function.
463
+ // to already freed data. Such situation may occur in following circumstances:
464
+ // 1. Joining cancelled thread - in such situation it may happen that pthread data will
465
+ // already be removed by handling 'cancelDone' message.
466
+ // 2. Joining thread from non-main browser thread (this also includes thread running main()
467
+ // when compiled with `PROXY_TO_PTHREAD`) - in such situation it may happen that following
468
+ // code flow occur (MB - Main Browser Thread, S1, S2 - Worker Threads):
469
+ // S2: thread ends, 'exit' message is sent to MB
470
+ // S1: calls pthread_join(S2), this causes:
471
+ // a. S2 is marked as detached,
472
+ // b. 'cleanupThread' message is sent to MB.
473
+ // MB: handles 'exit' message, as thread is detached, so returnWorkerToPool()
474
+ // is called and all thread related structs are freed/released.
475
+ // MB: handles 'cleanupThread' message which calls this function.
472
476
if ( pthread ) {
473
477
{ { { makeSetValue ( 'pthread_ptr' , C_STRUCTS . pthread . self , 0 , 'i32' ) } } } ;
474
478
var worker = pthread . worker ;
0 commit comments