Updating a file using random access
If you do not exercise proper care, it is possible that inconsistent values are read and/or propagated. One solution to manage access to a shared resource across threads is to use a lock.
A thread must acquire the lock before accessing a shared resource.
methods all advance the file pointer to the next byte, so only one positioning statement is required per record, unless you are reading randomly within the record.
The following code example positions the file pointer to position ptr, and reads a string of 28 characters followed by two doubles.
Note that, as with any string processing, the actual results will depend on the current encoding.
This is the function and it does not use locking for accessing the shared resource.
And here is the main part of the program to create and start multiple threads to run the function above.