thread/{Thread,Id}: use defaul-initialized pthread_t as "undefined" value

Use the "==" operator instead of pthread_equal().

This allows us to eliminate two boolean flags which are there to avoid
race conditions, and made the thing so fragile that I got tons of
(correct) thread sanitizer warnings.
This commit is contained in:
Max Kellermann
2017-12-22 10:37:07 +01:00
parent 6439727afc
commit 6a8c2848f6
3 changed files with 19 additions and 50 deletions

View File

@@ -35,23 +35,10 @@ Thread::Start()
if (handle == nullptr)
throw MakeLastError("Failed to create thread");
#else
#ifndef NDEBUG
creating = true;
#endif
int e = pthread_create(&handle, nullptr, ThreadProc, this);
if (e != 0) {
#ifndef NDEBUG
creating = false;
#endif
if (e != 0)
throw MakeErrno(e, "Failed to create thread");
}
defined = true;
#ifndef NDEBUG
creating = false;
#endif
#endif
}
@@ -67,23 +54,13 @@ Thread::Join() noexcept
handle = nullptr;
#else
pthread_join(handle, nullptr);
defined = false;
handle = pthread_t();
#endif
}
inline void
Thread::Run() noexcept
{
#ifndef _WIN32
#ifndef NDEBUG
/* this works around a race condition that causes an assertion
failure due to IsInside() spuriously returning false right
after the thread has been created, and the calling thread
hasn't initialised "defined" yet */
defined = true;
#endif
#endif
f();
#ifdef ANDROID