From 24455f88af13d577177765070ea35cbf53dc1af5 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] src: check for tsfn in conditional_variable wait Fixes: #1150 PR-URL: https://github.com/nodejs/node-addon-api/pull/1168 Reviewed-By: Michael Dawson 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(); };