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") remover()9void remover() 10 { 11 while(1) 12 { 13 boost::filesystem::remove(FNAME); 14 } 15 } 16 creater()17void creater() 18 { 19 for(int i=0; i<100000; i++) std::fstream(FNAME, std::fstream::out); 20 } 21 main()22int 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 } 39