unix,win: wait for threads to start
It appears that, at least on Windows, the process terminates abnormally when the program exits before the worker threads complete initializing. Wait for the threads to spin up in `init_threads()` to avoid that. Refs: https://github.com/libuv/libuv/pull/1613#issuecomment-344958863 PR-URL: https://github.com/libuv/libuv/pull/1639 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
c5dd2d4218
commit
5486f6bd51
@ -38,7 +38,6 @@ static uv_thread_t* threads;
|
||||
static uv_thread_t default_threads[4];
|
||||
static QUEUE exit_message;
|
||||
static QUEUE wq;
|
||||
static volatile int initialized;
|
||||
|
||||
|
||||
static void uv__cancelled(struct uv__work* w) {
|
||||
@ -105,7 +104,7 @@ static void post(QUEUE* q) {
|
||||
UV_DESTRUCTOR(static void cleanup(void)) {
|
||||
unsigned int i;
|
||||
|
||||
if (initialized == 0)
|
||||
if (nthreads == 0)
|
||||
return;
|
||||
|
||||
post(&exit_message);
|
||||
@ -122,7 +121,6 @@ UV_DESTRUCTOR(static void cleanup(void)) {
|
||||
|
||||
threads = NULL;
|
||||
nthreads = 0;
|
||||
initialized = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -130,6 +128,7 @@ UV_DESTRUCTOR(static void cleanup(void)) {
|
||||
static void init_threads(void) {
|
||||
unsigned int i;
|
||||
const char* val;
|
||||
int spin;
|
||||
|
||||
nthreads = ARRAY_SIZE(default_threads);
|
||||
val = getenv("UV_THREADPOOL_SIZE");
|
||||
@ -161,7 +160,11 @@ static void init_threads(void) {
|
||||
if (uv_thread_create(threads + i, worker, NULL))
|
||||
abort();
|
||||
|
||||
initialized = 1;
|
||||
do {
|
||||
uv_mutex_lock(&mutex);
|
||||
spin = (idle_threads < nthreads);
|
||||
uv_mutex_unlock(&mutex);
|
||||
} while (spin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user