[dmd-concurrency] CSP: Communicating sequential processes
Pelle Månsson
pelle.mansson at gmail.com
Wed Jan 20 05:23:28 PST 2010
You aren't supposed to write when you have a readers lock, I think it
should deadlock.
On Wed, Jan 20, 2010 at 1:28 PM, Michel Fortin
<michel.fortin at michelf.com> wrote:
> Le 2010-01-20 à 2:07, Sean Kelly a écrit :
>
> What happens if you call test() here?
>
> void test() {
> synchronized (mut.reader) {
> // read A
> testWrite();
> // read B
> }
> }
>
> void testWrite() {
> syncrhonized (mut.writer) {
> // write C
> }
> }
>
> I guess that if you haven't implemented upgrades this will deadlock.
>
> I'd like to note that even upgrading the lock to a write lock might be a problem: as I said in my other message, making this an automatic upgrade might force the release the reader lock until the writer lock is acquired, which would be unexpected from test()'s point of view.
>
> This could work well as a transaction, where a failure to upgrade the lock would throw an exception, "read A" would be rollbacked, and the synchronized part would be attempted again. But without proper logic to deal with the unfortunate case of a failed upgrade you have either a race or a deadlock here.
>
> --
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
>
>
>
> _______________________________________________
> dmd-concurrency mailing list
> dmd-concurrency at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-concurrency
>
More information about the dmd-concurrency
mailing list