@@ -183,41 +183,22 @@ var LibraryPThread = {
183
183
// some operations that leave the worker queue in an invalid state until
184
184
// we are completely done (it would be bad if free() ends up calling a
185
185
// queued pthread_create which looks at the global data structures we are
186
- // modifying).
187
- PThread . runWithoutMainThreadQueuedCalls ( function ( ) {
188
- delete PThread . pthreads [ worker . pthread . threadInfoStruct ] ;
189
- // Note: worker is intentionally not terminated so the pool can
190
- // dynamically grow.
191
- PThread . unusedWorkers . push ( worker ) ;
192
- PThread . runningWorkers . splice ( PThread . runningWorkers . indexOf ( worker ) , 1 ) ;
193
- // Not a running Worker anymore
194
- __emscripten_thread_free_data ( worker . pthread . threadInfoStruct ) ;
195
- // Detach the worker from the pthread object, and return it to the
196
- // worker pool as an unused worker.
197
- worker . pthread = undefined ;
198
- } ) ;
199
- } ,
200
- // Runs a function with processing of queued calls to the main thread
201
- // disabled. This is useful to avoid something like free() ending up waiting
202
- // for a lock, then running processing events, and those events can end up
203
- // doing things that interfere with what we were doing before (for example,
204
- // if we are tearing down a thread, calling free to erase its data could
205
- // end up calling a proxied pthread_create, which gets a free worker, and
206
- // can interfere).
207
- // This is only safe to call if we do not need queued calls to run. That is
208
- // the case when doing something like free(), which just needs the malloc
209
- // lock to be released.
210
- runWithoutMainThreadQueuedCalls : function ( func ) {
211
- #if ASSERTIONS
212
- assert ( PThread . mainRuntimeThread , 'runWithoutMainThreadQueuedCalls must be done on the main runtime thread' ) ;
213
- assert ( __emscripten_allow_main_runtime_queued_calls ) ;
214
- #endif
215
- HEAP32 [ __emscripten_allow_main_runtime_queued_calls >> 2 ] = 0 ;
216
- try {
217
- func ( ) ;
218
- } finally {
219
- HEAP32 [ __emscripten_allow_main_runtime_queued_calls >> 2 ] = 1 ;
220
- }
186
+ // modifying). To achieve that, defer the free() til the very end, when
187
+ // we are all done.
188
+ var pthread_ptr = worker . pthread . threadInfoStruct ;
189
+ delete PThread . pthreads [ pthread_ptr ] ;
190
+ // Note: worker is intentionally not terminated so the pool can
191
+ // dynamically grow.
192
+ PThread . unusedWorkers . push ( worker ) ;
193
+ PThread . runningWorkers . splice ( PThread . runningWorkers . indexOf ( worker ) , 1 ) ;
194
+ // Not a running Worker anymore
195
+ // Detach the worker from the pthread object, and return it to the
196
+ // worker pool as an unused worker.
197
+ worker . pthread = undefined ;
198
+
199
+ // Finally, free the underlying (and now-unused) pthread structure in
200
+ // linear memory.
201
+ __emscripten_thread_free_data ( pthread_ptr ) ;
221
202
} ,
222
203
receiveObjectTransfer : function ( data ) {
223
204
#if OFFSCREENCANVAS_SUPPORT
0 commit comments