]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/test/issues/11166-remove-race.cpp
update ceph source to reef 18.1.2
[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++)
20 std::fstream(FNAME, std::fstream::out);
21 }
22
23 int main()
24 {
25 boost::filesystem::remove(FNAME);
26 boost::filesystem::remove(FNAME);
27
28 std::cout << "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();
37 r1.join();
38 r2.interrupt();
39 r2.join();
40 }