Unblocking on a shared monitor

View: New views
6 Messages — Rating Filter:   Alert me  

Unblocking on a shared monitor

by Cássio M. M. Pereira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Let's assume I have three threads trying to get the monitor of a
shared object. Thread-1 gets the exclusive access to a synchronized
code block, while Thread-2 and Thread-3 remain blocked. What is the
priority of unblocking the two threads when Thread-1 releases the lock
?

Assume Thread-2 asked for the lock a moment before Thread-3. Is FIFO guaranteed?

I couldn't find this in the Java language specification, but I've been
told there's no order guarantee.

Thank you,
Cássio.

--
Cássio M. M. Pereira
_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users

Re: Unblocking on a shared monitor

by Orion Letizi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You're right.  There's no order guarantee.

--Orion

On Apr 6, 2008, at 8:24 PM, Cássio M. M. Pereira wrote:

> Let's assume I have three threads trying to get the monitor of a
> shared object. Thread-1 gets the exclusive access to a synchronized
> code block, while Thread-2 and Thread-3 remain blocked. What is the
> priority of unblocking the two threads when Thread-1 releases the lock
> ?
>
> Assume Thread-2 asked for the lock a moment before Thread-3. Is FIFO  
> guaranteed?
>
> I couldn't find this in the Java language specification, but I've been
> told there's no order guarantee.
>
> Thank you,
> Cássio.
>
> --
> Cássio M. M. Pereira
> _______________________________________________
> tc-users mailing list
> tc-users@...
> http://lists.terracotta.org/mailman/listinfo/tc-users

_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users

Re: Unblocking on a shared monitor

by Cássio M. M. Pereira :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, so how can we avoid starvation?

If more threads start blocking on the monitor, how can we be sure that
Thread-2 will eventually grab the lock?

Thanks,
Cássio

On Mon, Apr 7, 2008 at 12:59 AM, Orion Letizi <orion@...> wrote:

> You're right.  There's no order guarantee.
>
>  --Orion
>
>
>
>  On Apr 6, 2008, at 8:24 PM, Cássio M. M. Pereira wrote:
>  > Let's assume I have three threads trying to get the monitor of a
>  > shared object. Thread-1 gets the exclusive access to a synchronized
>  > code block, while Thread-2 and Thread-3 remain blocked. What is the
>  > priority of unblocking the two threads when Thread-1 releases the lock
>  > ?
>  >
>  > Assume Thread-2 asked for the lock a moment before Thread-3. Is FIFO
>  > guaranteed?
>  >
>  > I couldn't find this in the Java language specification, but I've been
>  > told there's no order guarantee.
>  >
>  > Thank you,
>  > Cássio.
>  >
>  > --
>  > Cássio M. M. Pereira
>  > _______________________________________________
>  > tc-users mailing list
>  > tc-users@...
>  > http://lists.terracotta.org/mailman/listinfo/tc-users
>
>  _______________________________________________
>  tc-users mailing list
>  tc-users@...
>  http://lists.terracotta.org/mailman/listinfo/tc-users
>



--
Cássio M. M. Pereira
_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users

Re: Unblocking on a shared monitor

by Orion Letizi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here' s an interesting section of a book called "Java Threads" by  
Scott Oaks and Henry Wong on lock fairness that might shed some light:

http://books.google.com/books?id=gekyqm8epMkC&pg=PA65&lpg=PA65&dq=java+lock+fairness&source=web&ots=0AVfLA4sup&sig=LeGaSaRXrqPszn2Oub3dFteLRq8&hl=en#PPA65,M1

--Orion

On Apr 7, 2008, at 4:32 AM, Cássio M. M. Pereira wrote:

> Ok, so how can we avoid starvation?
>
> If more threads start blocking on the monitor, how can we be sure that
> Thread-2 will eventually grab the lock?
>
> Thanks,
> Cássio
>
> On Mon, Apr 7, 2008 at 12:59 AM, Orion Letizi <orion@...>  
> wrote:
>> You're right.  There's no order guarantee.
>>
>> --Orion
>>
>>
>>
>> On Apr 6, 2008, at 8:24 PM, Cássio M. M. Pereira wrote:
>>> Let's assume I have three threads trying to get the monitor of a
>>> shared object. Thread-1 gets the exclusive access to a synchronized
>>> code block, while Thread-2 and Thread-3 remain blocked. What is the
>>> priority of unblocking the two threads when Thread-1 releases the  
>>> lock
>>> ?
>>>
>>> Assume Thread-2 asked for the lock a moment before Thread-3. Is FIFO
>>> guaranteed?
>>>
>>> I couldn't find this in the Java language specification, but I've  
>>> been
>>> told there's no order guarantee.
>>>
>>> Thank you,
>>> Cássio.
>>>
>>> --
>>> Cássio M. M. Pereira
>>> _______________________________________________
>>> tc-users mailing list
>>> tc-users@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-users
>>
>> _______________________________________________
>> tc-users mailing list
>> tc-users@...
>> http://lists.terracotta.org/mailman/listinfo/tc-users
>>
>
>
>
> --
> Cássio M. M. Pereira
> _______________________________________________
> tc-users mailing list
> tc-users@...
> http://lists.terracotta.org/mailman/listinfo/tc-users

_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users

Re: Unblocking on a shared monitor

by Taylor Gautier-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Interestingly enough, Terracotta 2.5.x and lower is pretty much extremely fair.  In 2.6 we have added some unfairness, because it improves overall throughput.  I don't think you'll get starvation even in 2.6.


Orion Letizi wrote:
Here' s an interesting section of a book called "Java Threads" by  
Scott Oaks and Henry Wong on lock fairness that might shed some light:

http://books.google.com/books?id=gekyqm8epMkC&pg=PA65&lpg=PA65&dq=java+lock+fairness&source=web&ots=0AVfLA4sup&sig=LeGaSaRXrqPszn2Oub3dFteLRq8&hl=en#PPA65,M1

--Orion

On Apr 7, 2008, at 4:32 AM, Cássio M. M. Pereira wrote:
  
Ok, so how can we avoid starvation?

If more threads start blocking on the monitor, how can we be sure that
Thread-2 will eventually grab the lock?

Thanks,
Cássio

On Mon, Apr 7, 2008 at 12:59 AM, Orion Letizi orion@...  
wrote:
    
You're right.  There's no order guarantee.

--Orion



On Apr 6, 2008, at 8:24 PM, Cássio M. M. Pereira wrote:
      
Let's assume I have three threads trying to get the monitor of a
shared object. Thread-1 gets the exclusive access to a synchronized
code block, while Thread-2 and Thread-3 remain blocked. What is the
priority of unblocking the two threads when Thread-1 releases the  
lock
?

Assume Thread-2 asked for the lock a moment before Thread-3. Is FIFO
guaranteed?

I couldn't find this in the Java language specification, but I've  
been
told there's no order guarantee.

Thank you,
Cássio.

--
Cássio M. M. Pereira
_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users
        
_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users

      

-- 
Cássio M. M. Pereira
_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users
    

_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users
  

_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users

Re: Unblocking on a shared monitor

by Tim Eck :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Another bit of fun with java locks with regards to notifies

http://www.cs.kent.ac.uk/projects/ofa/java-threads/0.html

wot, no chickens?

> -----Original Message-----
> From: tc-users-bounces@... [mailto:tc-users-
> bounces@...] On Behalf Of Cássio M. M. Pereira
> Sent: Monday, April 07, 2008 4:33 AM
> To: tc-users@...
> Subject: Re: [tc-users] Unblocking on a shared monitor
>
> Ok, so how can we avoid starvation?
>
> If more threads start blocking on the monitor, how can we be sure that
> Thread-2 will eventually grab the lock?
>
> Thanks,
> Cássio
>
> On Mon, Apr 7, 2008 at 12:59 AM, Orion Letizi <orion@...>
> wrote:
> > You're right.  There's no order guarantee.
> >
> >  --Orion
> >
> >
> >
> >  On Apr 6, 2008, at 8:24 PM, Cássio M. M. Pereira wrote:
> >  > Let's assume I have three threads trying to get the monitor of a
> >  > shared object. Thread-1 gets the exclusive access to a synchronized
> >  > code block, while Thread-2 and Thread-3 remain blocked. What is the
> >  > priority of unblocking the two threads when Thread-1 releases the
> lock
> >  > ?
> >  >
> >  > Assume Thread-2 asked for the lock a moment before Thread-3. Is
FIFO

> >  > guaranteed?
> >  >
> >  > I couldn't find this in the Java language specification, but I've
> been
> >  > told there's no order guarantee.
> >  >
> >  > Thank you,
> >  > Cássio.
> >  >
> >  > --
> >  > Cássio M. M. Pereira
> >  > _______________________________________________
> >  > tc-users mailing list
> >  > tc-users@...
> >  > http://lists.terracotta.org/mailman/listinfo/tc-users
> >
> >  _______________________________________________
> >  tc-users mailing list
> >  tc-users@...
> >  http://lists.terracotta.org/mailman/listinfo/tc-users
> >
>
>
>
> --
> Cássio M. M. Pereira
> _______________________________________________
> tc-users mailing list
> tc-users@...
> http://lists.terracotta.org/mailman/listinfo/tc-users

_______________________________________________
tc-users mailing list
tc-users@...
http://lists.terracotta.org/mailman/listinfo/tc-users
LightInTheBox - Buy quality products at wholesale price