AFAIK there is no builtin support for locking in rebol (most likely
because of the platform-dependace issue), but if you're only concerned with
access by your own programs I know of two schemes for voluntary resource
locking that seem to work well.
One is to have a server that listens on a TCP port for lock and unlock
requests, and some client code to handle the locking on that side (I wrote a
script that does this for the REBOL script-writing contest a while back, you
can probably find it on rebol.org or buried somewhere on rebol.com, if not
then let me know and I'll send you a copy).
The other is to create/delete a directory as a lockfile - in theory only
one process can succeed in creating the same directory, but I'm not sure if
this is absolutly true on all platforms.
The following functions using this approach seem to work (at least on
Win98):
try-get-filelock: func [ file ] [
not error? try [
make-dir rejoin [ %file-lock- file "/" ]
]
]
free-filelock: func [ file ] [
delete rejoin [ %file-lock- file "/" ] return
]
get-filelock: func [ file retries /local retry ] [
retry: 0
while [not try-get-filelock file] [
wait 0.5
if (retry: retry + 1) > retries [ return false ]
]
return true
]
Hopefully this will do the trick for you, if not let me know, I'd be glad to
help (I need to actually put in some file locking in one of my CGI scripts
right now, so I need a usable solution for this myself. Unfortuantely I
can't use the client-server system I wrote with the web-hosting setup where
I have my CGI's...)
Cal Dixon ([EMAIL PROTECTED])
-><-
>From: [EMAIL PROTECTED]
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Subject: [REBOL] Locking mechanism
>Date: Mon, 27 Mar 2000 9:14:12 +0200
>
>Hi,
>
>is there a way to achieve locking in Rebol?
>I mean, physical or advisor locking to achieve controlled access to a
>resource (file, or others).
>This subject is pretty much platform-dependent, however it is an
>important issue when concurrent programs need to share access to common
>resources.
>
>Thanks,
>
>Mauro
>
><< bregolin.vcf >>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com