[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multi-threaded Readers/Writers Lock



On Sun, Sep 09, 2001, mulix wrote about "Re: Multi-threaded Readers/Writers Lock":
> do you need single writer multiple readers, or multiple/multiple? do you

What's a multiple-writers multiple-readers lock? If you allow multiple writers
concurrently, then why not allow reading in the same time too? Remember,
writers are also allowed to read! So now, if you allow multiple concurrent
writers *and* readers, why do you need a lock at all?

The usual readers/writers lock, as far as I know, is one that allows several
readers to read concurrently, but only one writer to write at a time (when
the writer is writing, readers are blocked too).

Typically recursive locking is not needed in well-written programs, and
the "upgradability" feature you outlined isn't necessary (though the latter
can come in handy to improve concurrency in some circumstances).

> > Does anybody knows of a ready-made ANSI C implementation?

It is not hard to write such a thing yourself, using mutexes and condition-
variables (the latter are essential to implementing a lock like you want).
But knowing a little of the theory behind it is recommended. If you're
looking for a good course in the Technion on this and related issues, try
"Parallel and Distributed Computing", given (or at least used to be given)
by the CS department.

Anyway, I bet that dozens of ANSI C implementations exist (if only as examples
in courses and/or pthread books), but I am afraid I don't know one to point
you too. Did you try googling?

-- 
Nadav Har'El                        |        Sunday, Sep  9 2001, 21 Elul 5761
nyh@math.technion.ac.il             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |I used to work in a pickle factory, until
http://nadav.harel.org.il           |I got canned.

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il