[Info-vax] counting-lock ?

Michael Moroney moroney at world.std.spaamtrap.com
Sun Oct 25 00:07:29 EDT 2009


Pierre <pierre.bru at gmail.com> writes:
>I have a DECnet object which can serve various known queries on a
>database. these queries are resource consuming and I don't want more
>than (say) n=5 of them of the same type to run at the same time. I
>want the other one to be queued up for further processing.

I think I have an algorithm that needs fleshing out.  You have a master
lock M as well as other locks, numbered 1 through n-1 (n=5 in this case).
A process tries to get the master lock in exclusive mode, waiting until it
can.  If it's waiting it normally means there are n processes running
already, but can also be transient.  If it gets the lock, it counts the
number of holders.  If it's less than n, it converts the master lock to
null mode, and gets an exclusive lock on one of the numbered locks.  
(this part needs work, but for now, assume it tries Lock 1 first, if it
can't get it immediately, it tries Lock 2, then lock 3 etc), then converts
the master lock to Null, allowing another process to get it.  If the
number of holders on the master lock = n, it does _not_ convert the lock
(thus blocking the next process) but instead requests access to all the
numbered locks. As long as the other processes hold these locks, the
process holding the master lock won't get any of them.  Once any of these
other processes exits, releasing one of the numbered locks, the process
holding the master lock in EX has that numbered lock, and converts the
master lock to NULL, allowing another process to run.



More information about the Info-vax mailing list