upload
This commit is contained in:
22
test/tsan_condvar_repro.cc
Normal file
22
test/tsan_condvar_repro.cc
Normal file
@@ -0,0 +1,22 @@
|
||||
// Khong mot dong nao cua vslam. Chi std::mutex + condition_variable, dung
|
||||
// khuon mau y het Channel<T>: mot luong cho co vi ngu, mot luong dat co.
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
std::mutex mu;
|
||||
std::condition_variable cv;
|
||||
bool flag = false;
|
||||
int main() {
|
||||
{ std::lock_guard<std::mutex> lk(mu); } // giong MakeReader: khoa roi tha
|
||||
std::thread th([]{
|
||||
std::unique_lock<std::mutex> lk(mu);
|
||||
cv.wait_for(lk, std::chrono::seconds(5), []{ return flag; });
|
||||
});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
{ std::lock_guard<std::mutex> lk(mu); flag = true; } // giong Close
|
||||
cv.notify_all();
|
||||
th.join();
|
||||
std::puts("xong");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user