Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flockfile() and funlockfile() question

Status
Not open for further replies.

qednick

Programmer
Jul 26, 2002
516
US
Hi again all,

back to my conversion to c/c++ cgi scripts on UNIX system... I want to know if the functions [tt]flockfile()[/tt] and [tt]funlockfile()[/tt] are sufficient to prevent corruption when writing to a file on the UNIX web server.

For example, if I was to write to a file using PERL, I would use the function [tt]flock()[/tt] to prevent any other instances of the same script from writing to the file at the same time and therefore corrupting it.

Any info would be appreciated...

Thanks!
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
I am unfamiliar with said functions, but I do know that you can use a semiphore and memory mapping to achieve the sharing of resources without data corruption. The memorymapping would let you read/write to the file simply as if the file were an array of charictors. The semiphore would achieve a ATOMIC operation (test-n-set) of a flag to tell other users of the state, it would also queue up the other users for you, fo you don't bur nclock cycles with a while loop arround the attempt to read/write.

Granted that these are a little more involved than simple function calls, but there is also a lot more power to them.

There are some really good resources about memory mapping and semiphores at: http://www.ecst.csuchico.edu/~beej/guide/ipc/

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top