• 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

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is deadlock? how it can be avoided ? between how many processes u can achive deadlock?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
deadlock is a situation which occurs
when two or more threads are waiting to gain control of a resource,Due to some reason the condition on which waiting threads rely on to gain control doesnot happen.
eg.
thread A must acess method1 before it can release Method2,but ThreadB cannot release Method1 until it gets hold of method2
Thread A
synchronized method2()
{
synchronized method1()
{
.....
.....
}
}
Thread B
synchronized method1()
{
synchronized method2()
{
.....
.....
}
}
if u want detail study of deadlock ,read Books on operating System Concepts
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The short answer to avoiding deadlock is to always access resources in the same order. If I'm holding A and waiting for B and you're holding B and waiting for A we're deadlocked. But if we both get A first then B we'll be sequenced properly.
To hide knowledge about the proper sequence, you might encapsulate it in a command object or a method that everybody always uses instead of direct access to the resources.
I recently read a neat web paper about a clever manager that takes a list of resources, sorts it, and gets locks in the sorted order. Then you can pass it any two or ten things and it will get the locks in the right order. I'll see if I can find that again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic