| |
 | Simple Locks for Data Files
By Danny Kalev, C++ Pro
|
Configuration files, a system's registry, and other data files are accessed by multiple processes and users. To prevent data corruption caused by multiple processes modifying the same file simultaneously, only one process at a time should be allowed to modify it. The following solution demonstrates a simple and portable technique for locking files without resorting to intricate platform-dependent services.

Most file systems allow multiple users to modify the same data file at once. As a result, the data therein might be lost or corrupt.

Use a lock file to ensure exclusive write access to a data file.
|
|
Find Out More
All DevX 10-Minute Solutions for C/C++
MKS Tookkit Documentation
DevX 10-Minute Solution: Implementing the 'Resource Acquisition Is Initialization' Idiom
 | TALK BACK |
Standard C++ doesn't define synchronization objects such as semaphores and mutexes, which would normally serve for locking resources. Would you like to see synchronization objects becoming an integral part of the Standard Library? Which potential problems can such a platform-neutral synchronization library incur and how would you tackle them?
 |
|