a question regarding nested synchronized()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

a question regarding nested synchronized()

Yechiel Feffer
a question regarding nested synchronized()

Hi

Say a Thread  does:===========

synchronized(objectA)
{
....Something

  synchronized(objectB)
  {
....Something

   objectB.wait()

  }
}

  my questions:

1. is the command  objectB.wait();, which is called by the thread  , releasing the lock on object A too, or does objectA remains locked

   since it is not the monitor used for the wait() ?  (My guess is that objectA remains locked)
2. If the answer to 1. is yes,  in which order are the locks released ?

Regrds,
Yechiel Fefer 



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

RE: a question regarding nested synchronized()

Paula Mangas
a question regarding nested synchronized()

 

Yechiel Fefer,

 

( 1 ) objectA remains locked.

( 2 ) the locks are released in the opposite order that the they were made; that means, using this kind of synchronization, you will always have something like this:

 

Lock A

   Lock B

      Lock C

      Unlock C

   Unlock B

Unlock A

 

Best regards,

Paula Mangas

 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Yechiel Feffer
Sent: segunda-feira, 20 de Fevereiro de 2006 13:16
To: [hidden email]
Subject: [concurrency-interest] a question regarding nested synchronized()

 

Hi

Say a Thread  does:===========

synchronized(objectA)
{
....Something

  synchronized(objectB)
  {
....Something

   objectB.wait()

  }
}

  my questions:

1. is the command  objectB.wait();, which is called by the thread  , releasing the lock on object A too, or does objectA remains locked

   since it is not the monitor used for the wait() ?  (My guess is that objectA remains locked)
2. If the answer to 1. is yes,  in which order are the locks released ?

Regrds,
Yechiel Fefer 

 


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest