Skip to content

Commit

Permalink
Switch coroutine wait to CondVar (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
komarevtsev-d committed Sep 16, 2024
1 parent 9fbc08e commit 06c7015
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cloud/blockstore/libs/endpoints_vhost/external_vhost_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class TEndpoint final

void Start() override
{
auto processStarted = NewPromise();
TCondVar processStarted;
// To avoid a race, we need to get the shared pointer in the calling
// thread and pass it to the background thread. This guaranteed that the
// background thread will deal with a live this.
Expand All @@ -610,14 +610,16 @@ class TEndpoint final
// PR_SET_PDEATHSIG which tracks the aliveness of the thread that
// spawned the process.
self->Process = self->StartProcess();
processStarted.SetValue();
processStarted.Signal();
self->ThreadProc();
};

std::thread(std::move(workFunc)).detach();
// Infinite time wait is safe here, since we are in the coroutine
// thread.
Executor->WaitFor(processStarted);
with_lock (Mutex) {
std::thread(std::move(workFunc)).detach();
// Infinite time wait is safe here, since we are in the coroutine
// thread.
processStarted.WaitI(Mutex);
}
}

TFuture<NProto::TError> Stop() override
Expand Down

0 comments on commit 06c7015

Please sign in to comment.