From af95413bfa4ac6ab7c247b19f62b6944356352c8 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Tue, 9 Dec 2008 12:38:27 +0000 Subject: [PATCH] Applied a patch from Philip Guenther: - assumed that pthread_create() and pthread_join() set errno. They don't: they return the error value instead --- sysbench/sb_logger.c | 12 ++++++++---- sysbench/sysbench.c | 15 +++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sysbench/sb_logger.c b/sysbench/sb_logger.c index aa541c9..590c936 100644 --- a/sysbench/sb_logger.c +++ b/sysbench/sb_logger.c @@ -461,15 +461,17 @@ int oper_handler_init(void) if (batch_mode) { + int err; pthread_mutex_init(&batch_mutex, NULL); pthread_cond_init(&batch_cond, NULL); /* Create batch thread */ pthread_attr_init(&batch_attr); - if (pthread_create(&batch_thread, &batch_attr, &batch_runner_proc, NULL) + if ((err = pthread_create(&batch_thread, &batch_attr, &batch_runner_proc, NULL)) != 0) { - log_errno(LOG_FATAL, "Batch thread creation failed"); + log_text(LOG_FATAL, "Batch thread creation failed, errno = %d (%s)", + err, strerror(err)); return 1; } batch_status = BATCH_STATUS_STOP; @@ -561,15 +563,17 @@ int oper_handler_done(void) if (batch_mode) { + int err; /* Stop the batch thread */ pthread_mutex_lock(&batch_mutex); batch_status = BATCH_STATUS_STOP; pthread_cond_signal(&batch_cond); pthread_mutex_unlock(&batch_mutex); - if (pthread_join(batch_thread, NULL)) + if ((err = pthread_join(batch_thread, NULL))) { - log_errno(LOG_FATAL, "Batch thread join failed"); + log_text(LOG_FATAL, "Batch thread join failed, errno = %d (%s)", + err, strerror(err)); return 1; } diff --git a/sysbench/sysbench.c b/sysbench/sysbench.c index e333a1e..da18635 100644 --- a/sysbench/sysbench.c +++ b/sysbench/sysbench.c @@ -412,7 +412,8 @@ void *runner_thread(void *arg) int run_test(sb_test_t *test) { unsigned int i; - + int err; + /* initialize test */ if (test->ops.init != NULL && test->ops.init() != 0) return 1; @@ -461,10 +462,11 @@ int run_test(sb_test_t *test) { if (sb_globals.error) return 1; - if (pthread_create(&(threads[i].thread), &thread_attr, &runner_thread, - (void*)&(threads[i])) != 0) + if ((err = pthread_create(&(threads[i].thread), &thread_attr, &runner_thread, + (void*)&(threads[i]))) != 0) { - log_errno(LOG_FATAL, "Thread #%d creation failed", i); + log_text(LOG_FATAL, "Thread #%d creation failed, errno = %d (%s)", + i, err, strerror(err)); return 1; } } @@ -473,9 +475,10 @@ int run_test(sb_test_t *test) log_text(LOG_NOTICE, "Threads started!\n"); for(i = 0; i < sb_globals.num_threads; i++) { - if(pthread_join(threads[i].thread, NULL)) + if((err = pthread_join(threads[i].thread, NULL)) != 0) { - log_errno(LOG_FATAL, "Thread #%d join failed", i); + log_text(LOG_FATAL, "Thread #%d join failed, errno = %d (%s)", + i, err, strerror(err)); return 1; } }