From 796f4e1226befe1b45c8fe57fc3cc72391a0050c Mon Sep 17 00:00:00 2001 From: Will Date: Sat, 5 Oct 2013 12:23:09 +0900 Subject: [PATCH] handle failure to create event loop --- src/wrk.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wrk.c b/src/wrk.c index 5ac2618..075c7d0 100644 --- a/src/wrk.c +++ b/src/wrk.c @@ -134,6 +134,7 @@ int main(int argc, char **argv) { for (uint64_t i = 0; i < cfg.threads; i++) { thread *t = &threads[i]; + t->loop = aeCreateEventLoop(10 + cfg.connections * 3); t->connections = connections; t->stop_at = stop_at; @@ -151,9 +152,9 @@ int main(int argc, char **argv) { } } - if (pthread_create(&t->thread, NULL, &thread_main, t)) { + if (!t->loop || pthread_create(&t->thread, NULL, &thread_main, t)) { char *msg = strerror(errno); - fprintf(stderr, "unable to create thread %"PRIu64" %s\n", i, msg); + fprintf(stderr, "unable to create thread %"PRIu64": %s\n", i, msg); exit(2); } } @@ -225,10 +226,9 @@ int main(int argc, char **argv) { void *thread_main(void *arg) { thread *thread = arg; + aeEventLoop *loop = thread->loop; - aeEventLoop *loop = aeCreateEventLoop(10 + cfg.connections * 3); - thread->cs = zmalloc(thread->connections * sizeof(connection)); - thread->loop = loop; + thread->cs = zmalloc(thread->connections * sizeof(connection)); tinymt64_init(&thread->rand, time_us()); thread->latency = stats_alloc(100000);