unix: don't reap threads if none were started
Fixes a segmentation fault on 32 bits linux with glibc 2.15. Thanks to Johan Bergström (@jbergstroem) for reporting the issue and testing out the patch.
This commit is contained in:
parent
f7c991f1ce
commit
40134c3537
@ -31,6 +31,7 @@ static pthread_once_t once = PTHREAD_ONCE_INIT;
|
||||
static pthread_t threads[4];
|
||||
static ngx_queue_t exit_message;
|
||||
static ngx_queue_t wq = { &wq, &wq };
|
||||
static volatile int initialized;
|
||||
|
||||
|
||||
static void* worker(void* arg) {
|
||||
@ -89,6 +90,8 @@ static void init_once(void) {
|
||||
for (i = 0; i < ARRAY_SIZE(threads); i++)
|
||||
if (pthread_create(threads + i, NULL, worker, NULL))
|
||||
abort();
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
|
||||
@ -97,11 +100,14 @@ static void cleanup(void) {
|
||||
unsigned int i;
|
||||
int err;
|
||||
|
||||
if (initialized == 0)
|
||||
return;
|
||||
|
||||
post(&exit_message);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(threads); i++) {
|
||||
err = pthread_join(threads[i], NULL);
|
||||
assert(err == 0 || err == EINVAL || err == ESRCH);
|
||||
assert(err == 0 || err == ESRCH);
|
||||
(void) err; /* Silence compiler warning in release builds. */
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user