Subject : locks, semaphores, and such [message #29070] |
Sat, 26 January 2002 20:27 |
Ken Mankoff
Messages: 158 Registered: February 2000
|
Senior Member |
|
|
Hi,
I need to create a unique directory to do some work in. This is a
web-based IDL script (through ION), and multiple people may access the
site at the same second. Each user gets their images generated in a
uniquely named directory, which is then deleted 5 minutes later...
I know a bunch about semaphores and threads and stuff like that, but
here is the problem. The "threads" (users) do not have inter-thread
communication, unless its through files on disk. If they did, this
would be a perfect use for COMMON blocks. Also, the web server has 2
CPUs so much of the traditional semaphore logic is invalid, as both
threads can acquire a lock on the same clock cycle.
---
Here is the code I currently use to lock a file:
uniq = strtrim( long( systime( 1 ) ), 2 )
repeat begin
uniq = uniq + 1L
f = findfile(uniq,count=cnt) ; [1] ; find unclaimed file
endrep until cnt eq 0 ; [2]
spawn, 'touch ' + file ; [3] ; claim file
spawn, 'rm ' + file + ' | at now + 5 minutes' ; free file later
Of course, there are multiple clock cycles and disk accesses between
when [1] loads a "0" into cnt, and when [3] finishes executing the
'touch' part of the command.
The system this runs on is 5 people on 5 computers using 5 different
IDL sessions all sharing 1 cross-mounted disk. So far, the bug has
never evolved into an error :)
---
At worst, can anyone think of a way to detect if multiple users got
assigned the same directory and at least fail gracefully? At best,
does anyone have an algorithm pre-built for just this purpose?
Thanks,
Ken Mankoff
--
Kenneth Mankoff
LASP://303.492.3264
http://lasp.colorado.edu/~mankoff/
http://lasp.colorado.edu/snoedata/
http://lasp.colorado.edu/marsrobot/
|
|
|