mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
Fix a race condition in cti::transforms::wait()
* Thanks to p4654545 for reporting this issue and providing a reproducible example * Closes #38
This commit is contained in:
parent
48c6abf5f2
commit
6bffb44d2b
@ -81,24 +81,26 @@ Result wait_relaxed(continuable_base<Data, Annotation>&& continuable) {
|
|||||||
return std::move(continuable).unpack();
|
return std::move(continuable).unpack();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mutex cv_mutex;
|
|
||||||
condition_variable_t cv;
|
condition_variable_t cv;
|
||||||
std::atomic_bool ready{false};
|
std::mutex cv_mutex;
|
||||||
|
|
||||||
|
bool ready{false};
|
||||||
Result sync_result;
|
Result sync_result;
|
||||||
|
|
||||||
std::move(continuable)
|
std::move(continuable)
|
||||||
.next([&](auto&&... args) {
|
.next([&](auto&&... args) {
|
||||||
sync_result = Result::from(std::forward<decltype(args)>(args)...);
|
sync_result = Result::from(std::forward<decltype(args)>(args)...);
|
||||||
|
|
||||||
ready.store(true, std::memory_order_release);
|
lock_t lock(cv_mutex);
|
||||||
|
ready = true;
|
||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
})
|
})
|
||||||
.done();
|
.done();
|
||||||
|
|
||||||
if (!ready.load(std::memory_order_acquire)) {
|
|
||||||
lock_t lock(cv_mutex);
|
lock_t lock(cv_mutex);
|
||||||
|
if (!ready) {
|
||||||
cv.wait(lock, [&] {
|
cv.wait(lock, [&] {
|
||||||
return ready.load(std::memory_order_acquire);
|
return ready;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user