From 46fd44c1042c9903b2f1ab87e9f200a13c7e702d Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 8 Jul 2014 19:53:28 -0700 Subject: [PATCH] thread: remove harmless race on status_ in End() if a thread was still doing work when End() was called there'd be a race on worker->status_. in these cases, however, the specific value is meaningless as it would be >= OK and the thread would have been shut down properly, but we'll check 'impl_' instead to avoid any potential TSan/DRD reports. Change-Id: Ib93cbc226a099f07761f7bad765549dffb8054b1 --- src/utils/thread.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/utils/thread.c b/src/utils/thread.c index 08ad4e1f..264210ba 100644 --- a/src/utils/thread.c +++ b/src/utils/thread.c @@ -269,18 +269,19 @@ static void Launch(WebPWorker* const worker) { } static void End(WebPWorker* const worker) { - if (worker->status_ >= OK) { #ifdef WEBP_USE_THREAD + if (worker->impl_ != NULL) { ChangeState(worker, NOT_OK); pthread_join(worker->impl_->thread_, NULL); pthread_mutex_destroy(&worker->impl_->mutex_); pthread_cond_destroy(&worker->impl_->condition_); -#else - worker->status_ = NOT_OK; -#endif + WebPSafeFree(worker->impl_); + worker->impl_ = NULL; } - WebPSafeFree(worker->impl_); - worker->impl_ = NULL; +#else + worker->status_ = NOT_OK; + assert(worker->impl_ == NULL); +#endif assert(worker->status_ == NOT_OK); }