S. Nikolov - 2006-05-05

Logged In: YES
user_id=1253319

Frogive me for butting in (I am not affiliated with Judy).
You can't get away with locking just writers, you know why?
This is how RW locks work: imagine you have 10 readers
concurently accessing a data struct and no preexisting
writers (the reference count in the lock is 10, writer bit
is off); now a writer comes along - it sets the writer bit
to on and blocks until all 10 readers have finished; any new
readers that attempt to grab the lock would be blocked
meanwhile because the writer bit is set. You can think of
the lock as a long variable where say 20 bit are used for
ref. counting, 1 bit for r/w indication and the remaining
ones for other purposes. Last clue, you can atomically turn
any bit pattern into any other bit pattern, that's key to
how rw locks are implemented.

I just showed you that readers can block as much as writers
can. On the subject of adding thread safety to judy, I'd say
sure why not if it doesn't bind me to a particular API such
as win32 or pthread mutexes. If I want to use judy inside an
OS kernel then no particular implementation of locks can be
assumed.