feat use atomic
All checks were successful
ci/pr/linux-aarch64-gcc/1 Pipeline was successful
ci/pr/linux-aarch64-gcc/2 Pipeline was successful
ci/pr/linux-x64-gcc/1 Pipeline was successful
ci/pr/linux-x64-gcc/2 Pipeline was successful
ci/pull_request_closed/linux-aarch64-gcc/1 Pipeline was successful
ci/pull_request_closed/linux-aarch64-gcc/2 Pipeline was successful
ci/pull_request_closed/linux-x64-gcc/1 Pipeline was successful
ci/pull_request_closed/linux-x64-gcc/2 Pipeline was successful
ci/push/linux-aarch64-gcc/1 Pipeline was successful
ci/push/linux-aarch64-gcc/2 Pipeline was successful
ci/push/linux-x64-gcc/1 Pipeline was successful
ci/push/linux-x64-gcc/2 Pipeline was successful

This commit is contained in:
tqcq 2024-08-11 12:46:32 +08:00
parent 9830a33ea9
commit 9bad174e0e

View File

@ -51,7 +51,7 @@ protected:
protected: protected:
Mutex *m; Mutex *m;
CondVar *cv; CondVar *cv;
bool is_started; std::atomic<bool> is_started;
bool is_set; bool is_set;
bool is_timeout; bool is_timeout;
std::thread *worker; std::thread *worker;
@ -64,11 +64,13 @@ TEST_F(CondVarTest, NotifyOne_Wait) {
// UniqueLock<Mutex> inner_locker(*m); // UniqueLock<Mutex> inner_locker(*m);
// cv->Wait(inner_locker); // cv->Wait(inner_locker);
ScopedLock inner_locker(*m); ScopedLock inner_locker(*m);
SetStarted();
cv->Wait(inner_locker); cv->Wait(inner_locker);
is_set = true; is_set = true;
cv->NotifyOne(); cv->NotifyOne();
}); });
WaitStarted();
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
ASSERT_FALSE(is_set); ASSERT_FALSE(is_set);