----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 02, 1999 11:17 PM
Subject: [REBOL] How to open a file exclusively? Re:(2)
>
>
> [EMAIL PROTECTED] wrote:
>
> > ----- Original Message -----
> > From: <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, December 02, 1999 6:51 AM
> > Subject: [REBOL] How to open a file exclusively?
> >
> > > Hi,
> > >
> > > is there any possibility to open file exclusively (lock it) in REBOL?
It
> > > doesn't seem any refinement can do it. Maybe some open/exclusive
> > > refinement wouldn't be so hard to add? It would be usefull for file
> > > based semaphores ....
> >
> > Can you set that file hidden, so the other apps can't even see it? Or
check
> > the archive setting? Or change the extension or the name? Or set it
> > read-only? Dos is limited in this stuff.
> >
> > The following is NOT code, obviously:
> > 1) i want file test.txt
> > 2a) change it's name to test_inuse_by_code1.txt
> > 2b) if the app is #2, it's test_inuse_by_code2.txt
> > 2c) or set the other semaphores as bit tests in the name: test_bits.txt
> > 2d) or a separate file of attributes, test_atts.txt contains them.
> > 3) use the file
> > 4) change the name back when done.
>
> But I think it doesn't solve one problem for me. I need to know, if app is
> still running. If some app crashes, it will let file in unwanted state
(e.g.
> renamed), so I would like to check, if it is possible to open it, to see
> appropriate app still holds the lock to it ...
That's one of those little headaches in multitasking, its how some
multitasking boxes had two P-300's running an app as fast as a single P-90,,
it's all that handshaking. No matter how you handle the flags, if the app
crashes, it can't release it. I don't know that OSs will do it for you
either, linux may, i don't know,, but i know win95 won't, i've had to reboot
to get access to a file again. In the apps i have written, like the bot, i
have 2-way handshaking going on via dde, so each app can tell if another app
is on, this saves starting multiple instances of the same app. Maybe you can
keep a monitor app running, it can query the others to see if they are
running, and they can query it to see if an app is running. Or you can query
windoze to see if thet dde name for that app is taken, win will free it's
dde name when the app is closed out normally. You may want to consider using
socks too, so you can have your apps talk across an intranet someday. One
nice thing about dde, if the msg can't be sent because the app died, windoze
doesn't complain,, but with socks, i expect a problem in Eu, cause you can't
have a timer trip and close the socket ( if it fails to send ) while the
program does other things. And if an app holding a socket open crashes, and
is restarted by you or another app, it can't grab the same socket, it was
never closed by the app that opened it, and another app can't close it,
cause another app won't know if it is validly in use.
Kat