Walter is right about transitive readonly - here's the alternative

Janice Caron caron800 at googlemail.com
Thu Sep 13 09:41:45 PDT 2007


On 9/13/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> And you have 2 threads running, both are simultaneously executing this code.
> If they both have a read lock, and want to upgrade to a write lock, who gets
> it first?

A write lock cannot be granted until /all/ read-locks are unlocked. If
another thread has a read lock, then that thread has a promise that
the data which the lock protects will not change. That's what a read
lock /means/. So you cannot "upgrade" a read lock into a write lock,
for the reason that multiple threads might simultaneously be trying to
do the same thing, and that would deadlock.



More information about the Digitalmars-d mailing list