Skip to content

Commit 24455f8

Browse files
KevinEadymhdawson
authored andcommitted
src: check for tsfn in conditional_variable wait
Fixes: #1150 PR-URL: #1168 Reviewed-By: Michael Dawson <midawson@redhat.com
1 parent 40ed7ce commit 24455f8

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

test/threadsafe_function/threadsafe_function_sum.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class DelayedTSFNTask {
8181
// Entry point for std::thread
8282
void entryDelayedTSFN(int threadId) {
8383
std::unique_lock<std::mutex> lk(mtx);
84-
cv.wait(lk);
84+
cv.wait(lk, [this] { return this->tsfn != nullptr; });
8585
tsfn.BlockingCall([=](Napi::Env env, Function callback) {
8686
callback.Call({Number::New(env, static_cast<double>(threadId))});
8787
});

test/typed_threadsafe_function/typed_threadsafe_function_sum.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class DelayedTSFNTask {
9999
// Entry point for std::thread
100100
void entryDelayedTSFN(int threadId) {
101101
std::unique_lock<std::mutex> lk(mtx);
102-
cv.wait(lk);
102+
cv.wait(lk, [this] { return this->tsfn != nullptr; });
103103
tsfn.BlockingCall(new double(threadId));
104104
tsfn.Release();
105105
};

0 commit comments

Comments
 (0)