File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,16 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
3434 SetError (" test error" );
3535 }
3636 ProgressData data{0 };
37- std::unique_lock<std::mutex> lock (_cvm);
37+
3838 for (int32_t idx = 0 ; idx < _times; idx++) {
3939 data.progress = idx;
4040 progress.Send (&data, 1 );
41- _cv.wait (lock);
41+
42+ {
43+ std::unique_lock<std::mutex> lk (_cvm);
44+ _cv.wait (lk, [this ] { return dataSent; });
45+ dataSent = false ;
46+ }
4247 }
4348 }
4449
@@ -48,7 +53,12 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
4853 Number progress = Number::New (env, data->progress );
4954 _progress.MakeCallback (Receiver ().Value (), {progress});
5055 }
51- _cv.notify_one ();
56+
57+ {
58+ std::lock_guard<std::mutex> lk (_cvm);
59+ dataSent = true ;
60+ _cv.notify_one ();
61+ }
5262 }
5363
5464 private:
@@ -59,6 +69,8 @@ class TestWorker : public AsyncProgressWorker<ProgressData> {
5969 : AsyncProgressWorker(cb, resource_name, resource) {
6070 _progress.Reset (progress, 1 );
6171 }
72+
73+ bool dataSent = false ;
6274 std::condition_variable _cv;
6375 std::mutex _cvm;
6476 int32_t _times;
You can’t perform that action at this time.
0 commit comments