]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/test/issues/11166-remove-race.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / filesystem / test / issues / 11166-remove-race.cpp
1 #include <boost/filesystem.hpp>
2 #include <boost/thread.hpp>
3 #include <fstream>
4
5 boost::condition_variable cond;
6 boost::mutex mut;
7
8 #define FNAME ("remove-test")
9 void remover()
10 {
11 while(1)
12 {
13 boost::filesystem::remove(FNAME);
14 }
15 }
16
17 void creater()
18 {
19 for(int i=0; i<100000; i++) std::fstream(FNAME, std::fstream::out);
20 }
21
22 int main()
23 {
24 boost::filesystem::remove(FNAME);
25 boost::filesystem::remove(FNAME);
26
27 std::cout <<
28 "If you got this far, it's OK to remove a file that doesn't exist\n"
29 "Now trying with one creator thread and two remover threads.\n"
30 "This is likely to crash after just a few seconds at most." <<
31 std::endl;
32
33 boost::thread c(creater), r1(remover), r2(remover);
34
35 c.join();
36 r1.interrupt(); r1.join();
37 r2.interrupt(); r2.join();
38 }