[REBOL] Re: Double trouble
From: sanghabum:aol at: 23-Jun-2001 17:21
[g--santilli--tiscalinet--it]
> S> Can anyone suggest a Rebol method (i.e. as far as possible
> S> OS-independent) way of my application detecting if there is
> S> already an instance of it running on the machine?
>
> Just an idea:
>
> ; at the start of the script
> if error? try [make-dir %temp-dir] [
> alert "Please close other instance first"
> halt
> ]
>
> ; rest of the script
>
> ; just before quitting...
> delete %temp-dir
>
> (If Windows's TCP stack wasn't completely broken, you could have
> simply opened a listen port instead...)
Hi Gabriele,
Thanks for the response. You've given me a pretty good indication that I
haven't overlooked an inbuilt Rebol mechanism,--- and you've replicated my
original thinking (which was forget about TCP stack; try getting a write lock
on a file).
I thought "write lock on file" rather than "does directory exist?" as that
lets me distinguish three cases:
--File doesn't exist: I'm the only instance.
--File does exist and I can't write to it: I'm a second instance and must
close.
--File does exists and I can write to it: I'm the only instance, but an
earlier one fell over; so maybe I've got some cleaning up to do.
However, I can't find any way of getting Rebol to place a write-lock on a
file--I can happily write to the same file from two Rebol instances without
getting the error response I need, e.g.:
Instance 1:
MyPort: open/write/direct make file! %doubleTroubleTest
insert myport "blah blah"
Instance 2:
MyPort: open/write/direct make file! %doubleTroubleTest
insert myport "blah blah"
Obviously, I can write a locking mechanism based on shared areas of a common
file. I can even (I think) make it air tight in race conditions. But I only
want to do that if there's no magic setting in a Port (or elsewhere) that
gives me a write-lock.
I've had a probe around and not found anything. Does anyone know better?
--Thanks,
--Colin.