for 500pts <> File Locking and Unlocking. How its work?
Posted on 2006-10-21
I have a structured file with only 2 records
File name : Gate.dts
Record Length: 3bytes
FileNo As Byte '1
atUse As Boolean '2
this file open by process 1 (P#2)
Close #400: Open strCachePath & "Gate.dts" For Random Shared As #400 Len = 3
read some data
Get #400, 1, Gate
write some data
Lock #400, 2
Gate.atUse = True
Put #400, 2, Gate
Unlock #400, 2
This two records are regulary update by a second Process (P#2) say every 30 seconds
Similary P#1 need to read and write data to Gate.dts
P#1 reading these records every 30 seconds or so
I'd like to give priority to P#2 if I can
1) when I reding data do I need to Lock and Unlock?
2) what will hapen if P#2 is writing to Gate.dts record 1 and P#1 want to read it same time? will it crash?
in this scenario P#1 and P#2 are in different computers connected though network. P#1 act like a server.
some occations there could be more than one clients and can have multiple of P#2 process and Gate.dts.
Gate.dts located in client machines only