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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Semaphores /File Access

Status
Not open for further replies.

Sherak

Programmer
Sep 1, 2003
83
GB
Hi,

I would like to run this by you and see if you think it is possible.

I am writing a program which can be run on severval machine over a pier to pier network, one of the machines is considered host and holds the main file which each client machine writes to (like a database I suppose).

I am trying to determine a way to control file access to avoid race conditions and deadlock, I have considered having another main file on the host with a switch and once the file has been taken by one program it sets a flag in the access file to 'taken' once it is finished with the file it remarks the file as 'free'. If the file is marked as taken all other programs must wait.

Race conditions arent a massive problem because each machine takes around 10 to 15 seconds to generate the data to be wrtiten however what I would like to know was if a program looks at the file and sees it as 'free' by the time the program writes 'taken' into the file, could another program come along and read the file as 'open' just a fraction of a second before the first program has manged to change it ?....

Any advice would be appriciated or even some differnt ways of implementing semaphores over a network ?..

Regards,

Paul Jackson.
 
Sherak,
Well if I were creating a client-server flat-file database system, I would have the server application control the read/write operations. That way only ONE application is actually opening the file.

The client programs could send the data requests and updates through a port or the could have a designated folder on the server system that the server app checks.

Then each cycle, the server app could check each port or "inbox" folder to see what requests/updates it has, perform those requests/updates and return a success (or data)back to the clients.

(but i probably wouldn't make a flat-file database client/server app...so the above is acedemic)

Good luck,
Chi Happens

Chi Happens
"When you know and respect your own inner nature, you know where you belong. You also know where you don't belong" - Benjamin Hoff
 
Kewl, let me know how it works out, or if you need some help.


Chi Happens

Chi Happens
"When you know and respect your own inner nature, you know where you belong. You also know where you don't belong" - Benjamin Hoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top