· May 10, 2016

File I/O: Exclusive Writes without blocking Readers

I have some logging code that outputs task status information to a log file. I would like to make the log available for reading while it is open for writing. The file is opened using the "L" option (Lock):

Open tLogFile:"WASL" Set tLogOpen=1

My intent was to prevent multiple processes from accidentally writing to the file and having messy output. Unfortunately, if the process is taking longer than expected, one can not simply open the log file to figure out what is going on because the "L" lock prevents the file from being opened for reading as well as writing.

Is there a simple way to enforce a single writer but allow many readers?

I am thinking that I may just have to take out a regular COS lock when opening the file, and release the lock when closing the file, but if I can just change the flags on the Open command, I would rather know how to do that.



Discussion (2)0
Log in or sign up to continue