Re: Reader Writer monitor in JAVA
From: A. Bolmarcich (aggedor_at_earl-grey.cloud9.net)
Date: 03/29/05
- Next message: Anton Spaans: "Re: Hwo to do Hello World From XSLT to JavaScript?"
- Previous message: meetselva_at_gmail.com: "Tiles"
- In reply to: Spliff Monkey: "Reader Writer monitor in JAVA"
- Next in thread: Spliff Monkey: "Re: Reader Writer monitor in JAVA"
- Reply: Spliff Monkey: "Re: Reader Writer monitor in JAVA"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Mar 2005 19:56:55 -0000
On 2005-03-29, Spliff Monkey <spliffmonkey@iname.com> wrote:
> I am trying to program a simple monitor for a multiple reader single
> writer problem in JAVA based on the pseudo code given at the bottom of
> this post. A link to my code is also given bellow.
>
> I get deadlock. I basically have producer and consumer classes which
> do nothing except call the Start_Read/Write and End_Read/Write from
> the monitor. I also have created a condition class.
>
> It seems as if, say, a consumer finishes its synchronized start_read.
> Then, say, a producer tries to write but is told to wait. Then the
> consumer just stops and never enters its end_read.
>
> The consumer should enter the end_read and then signal the producer.
>
> Does the producer waiting in the synchronized start_write, prevent the
> consumer entering the synchronized end_read?
Yes. In the sequence of events that you described, the Start_Read()
is synchronized on its Monitor object
invokes OK_to_Read.wait_() which
is synchronized on its Condition object (OK_to_Read)
invokes wait on its Condition object
This wait releases the synchronization lock on the Condition object; it
does not also release any other synchronization locks the thead has.
> If so how do I get around it.
You get around it by redesigning your solution so it does not deadlock.
> My code is here:
>
> http://www.maths.tcd.ie/~z/MainClass.java
In your code, your probably do not want the Start_Read method to use
the statement
readers +=readers;
- Next message: Anton Spaans: "Re: Hwo to do Hello World From XSLT to JavaScript?"
- Previous message: meetselva_at_gmail.com: "Tiles"
- In reply to: Spliff Monkey: "Reader Writer monitor in JAVA"
- Next in thread: Spliff Monkey: "Re: Reader Writer monitor in JAVA"
- Reply: Spliff Monkey: "Re: Reader Writer monitor in JAVA"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|