使用相同的线程来锁定和解锁文件。
如果使用scoped_lock,就不需要显式地锁定或解锁文件;锁定发生在构造器内,每当您退出该范围,就会自动发生解锁。
Using scoped_lock, you don't need to explicitly lock or unlock the file; the locking occurs inside the constructor, and the unlocking happens automatically whenever you exit the scope.
在解锁文件之前,通过调用 C 的 flush 库例程或 flush 方法(如果喜欢使用 C++ fstream 的话),刷新写入者进程中的数据。
Flush data in writer processes before unlocking a file by either calling C's flush library routine or the flush method (if you prefer a C++ fstream).
应用推荐