Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Lock and unlock a file
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01638353
Message ID:
01638384
Views:
60
>Hi,
>
>I was wondering if anybody would point potential problems with the following approach of locking and unlocking a file:
>
>
>*-- Lock file
>nHandle = fopen( 'MyFile', 0 )
>
>if nHandle < -1
>   *-- File not locked
>endif 
>
>*-- The code "nHandle = fopen( 'MyFile', 0 )" will return -1 for
>*-- any other user on another PC.  Correct?
>
>*-- Unlock file
>if nHandle > 0
>   fclose( nHandle )
>endif  
>
>
>
>I want also to be sure that if the user shuts down his/her computer, the lock on the file 'MyFile' is released.
>
>TIA

My new idea of doing the semaphore "locking" is to create and delete a semaphore file. That is, instead of locking a file, I will "play" with the approach of creating the file - during the time that the app needs to update the SQL table; and then erase this file. And I will add a "safety" code that if the file exists (for any user) for more than 10 seconds, delete this file. Therefore, if a user creates this semaphore file but then his PC crashes, the next user will only need to wait 10 seconds and then will delete the file.
Please let me know if you see "big holes" in this approach.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform