简体   繁体   中英

File Locking in C++ For simultaneous Read and Write Lock

How can i lock a file for read and write operation. That is If "ABC" file name is in Write lock, it also provide Read Lock on the same locked file. In normal case we want to wait till write operation completion.So if there any ways to acquire this kind of locking

Many programs simply use a lock file to signify that a certain file is currently in use for writing.

The lock file is later removed when done writing.

For example, when process #1 is about to start writing to file example , it creates file example.lock . Later when done writing, it simply removes example.lock .

When process #2 want to read from file example it first checks if file example.lock exists. If it does then the file is locked for write operations and process #2 will have to wait.

Boost的shared_mutex实现了读/写锁定。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM