-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix keepRuntimeAlive in the case where EXIT_RUNTIME=0 and noExitRunti…
…me is not referenced Essentially the `keepRuntimeAlive` was relying on the `noExitRuntime` variable being set based on `EXIT_RUNTIME` but when `noExitRuntime` was absent the `EXIT_RUNTIME` settings was being ignored and the runtime was exiting even though `EXIT_RUNTIME=0` was set (the default). Fixes: #20636
- Loading branch information
Showing
6 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <unistd.h> | ||
#include <pthread.h> | ||
#include <emscripten/console.h> | ||
|
||
void _emscripten_thread_set_strongref(pthread_t thread); | ||
|
||
pthread_mutex_t ready_lock = PTHREAD_MUTEX_INITIALIZER; | ||
pthread_cond_t ready_cond = PTHREAD_COND_INITIALIZER; | ||
_Atomic bool ready = false; | ||
|
||
void* thread_main(void* arg) { | ||
pthread_mutex_lock(&ready_lock); | ||
if (!ready) { | ||
pthread_cond_wait(&ready_cond, &ready_lock); | ||
} | ||
pthread_mutex_unlock(&ready_lock); | ||
emscripten_outf("Hello from thread"); | ||
return NULL; | ||
} | ||
|
||
int main() { | ||
pthread_t t; | ||
pthread_create(&t, NULL, thread_main, NULL); | ||
pthread_detach(t); | ||
emscripten_outf("thread created, returning from main"); | ||
|
||
// Make sure the thread output doesn't appear until after the above message | ||
pthread_mutex_lock(&ready_lock); | ||
ready = true; | ||
pthread_cond_signal(&ready_cond); | ||
pthread_mutex_unlock(&ready_lock); | ||
|
||
// This needed under node to make sure the process doesn't exit before the | ||
// thread is done. | ||
// TODO(sbc): We probably want all running threads to keep node from exiting | ||
// like they would under POSIX. | ||
_emscripten_thread_set_strongref(t); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thread created, returning from main | ||
Hello from thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters