[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:
parent
e11fa0372d
commit
a503b6222f
|
@ -916,17 +916,17 @@ void* PosixCondition<Thread>::ThreadStartRoutine(void* parameter) {
|
||||||
current_thread_ = thread;
|
current_thread_ = thread;
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(thread->handle_.state_mutex_);
|
std::unique_lock<std::mutex> lock(thread->handle_.state_mutex_);
|
||||||
if (create_suspended) {
|
thread->handle_.state_ =
|
||||||
thread->handle_.state_ = State::kSuspended;
|
create_suspended ? State::kSuspended : State::kRunning;
|
||||||
thread->handle_.state_signal_.wait(lock, [thread] {
|
|
||||||
return thread->handle_.state_ != State::kSuspended;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
thread->handle_.state_ = State::kRunning;
|
|
||||||
}
|
|
||||||
thread->handle_.state_signal_.notify_all();
|
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();
|
start_routine();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue