[threads linux] Free and signal suspended threads

Give other threads access to initially suspended threads by signalling
conditional variable before waiting for state to be changed again.
This commit is contained in:
Sandy Carter 2019-01-21 14:26:16 -05:00 committed by Rick Gibbed
parent e11fa0372d
commit a503b6222f
1 changed files with 8 additions and 8 deletions

View File

@ -916,17 +916,17 @@ void* PosixCondition<Thread>::ThreadStartRoutine(void* parameter) {
current_thread_ = thread;
{
std::unique_lock<std::mutex> lock(thread->handle_.state_mutex_);
if (create_suspended) {
thread->handle_.state_ = State::kSuspended;
thread->handle_.state_signal_.wait(lock, [thread] {
return thread->handle_.state_ != State::kSuspended;
});
} else {
thread->handle_.state_ = State::kRunning;
}
thread->handle_.state_ =
create_suspended ? State::kSuspended : State::kRunning;
thread->handle_.state_signal_.notify_all();
}
if (create_suspended) {
std::unique_lock<std::mutex> lock(thread->handle_.state_mutex_);
thread->handle_.state_signal_.wait(
lock, [thread] { return thread->handle_.state_ != State::kSuspended; });
}
start_routine();
{