Skip to content

Commit dce4aa0

Browse files
committed
Don't run pthread key dtors on application exit
It should only be run when a thread is exiting (or when pthread_exit is called). This reverts commit 6d3e78c and 5c7c713.
1 parent a46745d commit dce4aa0

File tree

6 files changed

+9
-16
lines changed

6 files changed

+9
-16
lines changed

src/library_pthread.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,10 @@ var LibraryPThread = {
917917

918918
__pthread_exit_js__deps: ['exit'],
919919
__pthread_exit_js: function(status) {
920-
if (!ENVIRONMENT_IS_PTHREAD) _exit(status);
921-
else PThread.threadExit(status);
920+
if (!ENVIRONMENT_IS_PTHREAD) {
921+
PThread.runExitHandlers();
922+
_exit(status);
923+
} else PThread.threadExit(status);
922924
// pthread_exit is marked noReturn, so we must not return from it.
923925
throw 'unwind';
924926
},

src/postamble_minimal.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ function run() {
2424
var ret = _main();
2525

2626
#if EXIT_RUNTIME
27-
#if USE_PTHREADS
28-
PThread.runExitHandlers();
29-
#endif
3027
callRuntimeCallbacks(__ATEXIT__);
3128
<<< ATEXITS >>>
3229
#endif
@@ -226,7 +223,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
226223
initRuntime(asm);
227224
#if USE_PTHREADS && PTHREAD_POOL_SIZE
228225
if (!ENVIRONMENT_IS_PTHREAD) loadWasmModuleToWorkers();
229-
#if !PTHREAD_POOL_DELAY_LOAD
226+
#if !PTHREAD_POOL_DELAY_LOAD
230227
else
231228
#endif
232229
ready();

src/preamble.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,6 @@ function exitRuntime() {
423423
<<< ATEXITS >>>
424424
#endif
425425
#if USE_PTHREADS
426-
#if EXIT_RUNTIME
427-
PThread.runExitHandlers();
428-
#endif
429426
PThread.terminateAllThreads();
430427
#endif
431428
runtimeExited = true;

tests/pthread/test_pthread_setspecific_mainthread.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <pthread.h>
99

1010
void destructor(void* arg) {
11-
// Note: this is never printed as destructors for thread-specific
12-
// data are ran after stdio is shutdown.
1311
printf("destructor: %ld\n", (long)arg);
1412
assert(arg == (void*)42);
1513
}
@@ -22,6 +20,7 @@ int main() {
2220
pthread_setspecific(key, (void*)42);
2321
val = pthread_getspecific(key);
2422
assert(val == (void*)42);
25-
printf("done!\n");
26-
return 0;
23+
// Explicitly call pthread_exit since destructors for thread-specific data
24+
// are not called on application exit (it's only called when a thread exits).
25+
pthread_exit(0);
2726
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
done!
1+
destructor: 42

tests/test_core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,8 +2335,6 @@ def test_pthread_cleanup(self):
23352335
@node_pthreads
23362336
def test_pthread_setspecific_mainthread(self):
23372337
self.set_setting('EXIT_RUNTIME')
2338-
# ensure ___stdio_exit is called
2339-
self.set_setting('FORCE_FILESYSTEM')
23402338
self.do_run_in_out_file_test('pthread/test_pthread_setspecific_mainthread.c')
23412339

23422340
@node_pthreads

0 commit comments

Comments
 (0)