【发布时间】:2012-06-26 18:41:33
【问题描述】:
我遇到了一些代码问题,该代码偶尔会抛出以下异常:
boost interprocess: no such file or directory
有多个代码访问同一组文件,但有些代码会将文件实时移动到不同的目录。 处理和移动文件的代码使用文件锁,例如
boost::interprocess::file_lock
代码中发生的过程如下: 1)程序1检查它要锁定的文件是否存在 2) 如果上述检查通过,则使用 file_lock 锁定文件
我认为问题在于,在第 1 步和第 2 步之间,程序 2 可以对程序 1 正在处理的文件使用 boost::filesystem::rename 并移动它。
如果两个程序同时运行,有什么办法可以防止这种情况发生?
【问题讨论】:
标签: c++ boost locking race-condition interprocess