lockFile.cxx 408 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <fstream>
  3. //if run serially, works fine
  4. //if run in parallel, someone will attempt to delete
  5. //a locked file, which will fail
  6. int main()
  7. {
  8. std::string fname = "lockedFile.txt";
  9. std::fstream fout;
  10. fout.open(fname.c_str(), std::ios::out);
  11. for(int i = 0; i < 10000; i++)
  12. {
  13. fout << "x";
  14. fout.flush();
  15. }
  16. fout.close();
  17. return std::remove("lockedFile.txt");
  18. }