Path: blob/main/system/lib/pthread/emscripten_yield.c
6171 views
#include <stdbool.h>1#include <sched.h>2#include <threads.h>34#include <emscripten/threading.h>56#include "syscall.h"7#include "threading_internal.h"89static _Atomic pthread_t crashed_thread_id = NULL;1011void _emscripten_thread_crashed() {12crashed_thread_id = pthread_self();13}1415static void dummy(double now)16{17}1819weak_alias(dummy, _emscripten_check_timers);2021void _emscripten_yield(double now) {22int is_runtime_thread = emscripten_is_main_runtime_thread();2324// When a secondary thread crashes, we need to be able to interrupt the main25// thread even if it's in a blocking/looping on a mutex. We want to avoid26// using the normal proxying mechanism to send this message since it can27// allocate (or otherwise itself crash) so use a low level atomic primitive28// for this signal.29if (is_runtime_thread) {30if (crashed_thread_id) {31// Mark the crashed thread as strongly referenced so that Node.js doesn't32// exit while the pthread is propagating the uncaught exception back to33// the main thread.34_emscripten_thread_set_strongref(crashed_thread_id);35// Return the event loop so we can handle the message from the crashed36// thread.37emscripten_exit_with_live_runtime();38}3940// This is no-op in programs that don't include use of itimer/alarm.41_emscripten_check_timers(now);4243// Assist other threads by executing proxied operations that are effectively44// singlethreaded.45emscripten_main_thread_process_queued_calls();46}47#ifdef EMSCRIPTEN_DYNAMIC_LINKING48else {49_emscripten_process_dlopen_queue();50}51#endif52}535455