Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Double trouble

From: lmecir:mbox:vol:cz at: 27-Jun-2001 17:48

Hi Pekr,
> lock: context [ > > sem-port-spec: func [path file-name][to-file join to-string path head
change
> find copy file-name "." ".SEM"] > > locked: copy [] > > get-lock: func [path file-name][ > semaphore: sem-port-spec path file-name
It looks to me, that 'semaphore will "leak" to the global context, although you didn't intend that
> ; file doesn't exist, or does exist, but semaphore can be closed
(dead one)
> either not exists? semaphore [ > ; store pair of file-name, opened port > append locked semaphore > append locked open/new/direct semaphore
looks like the lock isn't exclusive, there is a possibility for two concurrent scripts to obtain the semaphore
> true > ][ > ; semaphore does exist - is locked or dead one? (possible app
crash)
> either remove-sem-file semaphore [ > ; store pair of file-name, opened port > append locked semaphore > append locked open/new/direct semaphore > true > ][false] ; can't get lock, sorry ... > ] > ] > > close-lock: func [path file-name][ > semaphore: sem-port-spec path file-name > if found? find locked semaphore [ > close select locked semaphore > remove remove find locked semaphore > ] > > either remove-sem-file semaphore [true][false] > ] > > remove-sem-file: func [semaphore][either not error? try [delete > semaphore][true][false]] > > ] > > example: > > lock/get-lock target-path "file-name.txt" ; will
create
> file-name.sem on 'target-path > if not lock/get-lock [print "unable to lock file"] ; should
print
> "unable to lock file" message ... > probe lock/locked ;
will show
> you > lock/close-lock target-path "file-name.txt" ; will
unlock file
> ... so, the problem is, that unix will allow you to delete file even if
you would
> own regular lock. A little bit lame imo. > > -pekr- >
I have got an exclusive file-based multiplatform locking mechanism, but it is a part of a larger script and I should rewrite it as stand-alone before it can be presented here...