• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deadlocks and the scheduler

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deadlocks happen when there are two objects having synchronized blocks and two different threads trying to run the synchronized blocks while each one is holding onto a lock that the other needs.
Well, why can't a scheduler make sure that a thread won't go to sleep while it enters a synchronized block/method. In other words, why does a scheduler kick a thread away from running state while it is holding a key. Why can't it make sure that the thread releases a lock before it can be kicked out from running state or is put to sleep ?

Could that be a solution to fix potential deadlocks ?

Thanks,
Priti
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

priti manas duddilla wrote:
Well, why can't a scheduler make sure that a thread won't go to sleep while it enters a synchronized block/method. In other words, why does a scheduler kick a thread away from running state while it is holding a key.



Not sure what you mean by this. Whether a thread goes to sleep() or not is part of the code it is running. Are you suggesting that the sleep() method should no longer work when a lock is held?

Also, the only two states actively handled by the scheduler are running and runnable. Thread that are sleeping or blocked (waiting for a resource) are doing so because it is running code that requires it to be so. You can't actively run code when the current code is doing stuff like "waiting for the IO to complete from file". There is nothing to run.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

priti manas duddilla wrote:Why can't it make sure that the thread releases a lock before it can be kicked out from running state or is put to sleep ?

Could that be a solution to fix potential deadlocks ?



Well, that would definitely fix potential deadlocks. It will also make the locking mechanism useless to protect against any race condition related to anything that can block -- such as anything that uses the disk, uses the network, or even uses other locks.

Henry
 
Hug your destiny! And hug this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic