From 3e02505a8100cd4578eb3c928b03ee9d7609d5e9 Mon Sep 17 00:00:00 2001 From: Kevin Eady <8634912+KevinEady@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:05:55 +0200 Subject: [PATCH] Check for tsfn in conditional_variable wait Fixes: #1150 --- test/threadsafe_function/threadsafe_function_sum.cc | 2 +- test/typed_threadsafe_function/typed_threadsafe_function_sum.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/threadsafe_function/threadsafe_function_sum.cc b/test/threadsafe_function/threadsafe_function_sum.cc index 5134e5816..019b0cea7 100644 --- a/test/threadsafe_function/threadsafe_function_sum.cc +++ b/test/threadsafe_function/threadsafe_function_sum.cc @@ -81,7 +81,7 @@ class DelayedTSFNTask { // Entry point for std::thread void entryDelayedTSFN(int threadId) { std::unique_lock lk(mtx); - cv.wait(lk); + cv.wait(lk, [this] { return this->tsfn != nullptr; }); tsfn.BlockingCall([=](Napi::Env env, Function callback) { callback.Call({Number::New(env, static_cast(threadId))}); }); diff --git a/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc b/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc index 9add259c4..b36ab2837 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc +++ b/test/typed_threadsafe_function/typed_threadsafe_function_sum.cc @@ -99,7 +99,7 @@ class DelayedTSFNTask { // Entry point for std::thread void entryDelayedTSFN(int threadId) { std::unique_lock lk(mtx); - cv.wait(lk); + cv.wait(lk, [this] { return this->tsfn != nullptr; }); tsfn.BlockingCall(new double(threadId)); tsfn.Release(); };