• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Relinquishing  RSS feed

 
srival vas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can it ever happen that while a Thread has a lock
on an Object, the Operating System can relinquish the lock, and give the object to another Thread.
for ex:
Class A
{
public synchronized mA() {... }
public synchronized mB() {... }
}
There is a Thread X that calls mA, and then wants
to call mB immediately after mA is thro', can it ever happen that X looses the lock on A (in that split second), when it has finished executing mA and still to start mB.
assumptions :
I do not put any wait, sleep, yeild etc, and no interrupt thrown
anywhere.
thanks
 
Jerry Pulley
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. On exit from a synchronized statement or method a thread gives up the lock it acquired on entry, so not only can the thread lose the lock on the object when it exits method <code>mA</code>, it definitely will lose the lock.
jply
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!