[REBOL] how to do simple exclusive open (locking mechanism), without using tcp s
From: petr::krenzelok::trz::cz at: 6-Jun-2001 18:56
Hi,
today I just experimented with 'open and various refinements, but could not
find any easy way of how to acomplish simple locking mechanism ...
RT - why there is no open/exclusive? Would be very handy. Is there any
problem with multiplatform issues?
I tried using following function:
semaphore: func [path file-name /_open /_close][
semaphore-port: to-file join to-string path head change find copy
file-name "." ".SEM"
either _close [
either not error? try [delete semaphore-port][
;close semaphore-port
return true
][return false]
][
either not exists? semaphore-port [ ; ... does semaphore already
exists?
open/new/direct semaphore-port
return true
][
either semaphore/_close path file-name [ ; semaphore exists, try
to close it ...
open/new/direct semaphore-port
return true
][return false] ; we can't close existing semaphore, user can't
get lock ...
]
]
]
The function simply takes path and filename, and creates .sem file for each
concrete file name, which is being downloaded ...
But I found out strange behavior. Once I creat .sem file in one session, and
try to delete it in another one, there is delay of some X sec when I can
delete the file. After few seconds however, I seem to be unable to delete
semaphore, and that's what I wanted to do. So - why is there such delay? Or
just confusion on my side? :-)
Thanks,
-pekr-