• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

A deadlock thread question.

Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A. The program prints �ABBCAD�
B. The program prints �CDDACB�
C. The program prints �ADCBADBC�
D. The output is a non-deterministic point because of a possible deadlock condition.
E. The output is dependent on the threading model of the system the program is running on.
The answer is B,D. But I don't know why the B is correct when D is correct. In D, it said it is non-deterministic the print out sequence.
Anyone would explain it? thx.
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This situation should be recognized visually as a possible deadlock:
aThread grabs lock1
aThread grabs lock2
anotherThread grabs lock2
anotherThread grabs lock1
That is, several threads are locking the same locks in different order.
The deadlock could occur if:
aThread grabs lock1 and anotherThread is scheduled before it can grab lock2. anotherThread grabs lock2 but it cannot continue because lock1 is owned by aThread, thus it blocks waiting for lock1 tob released. Now aThread is scheduled again and tries to get lock2, but it blocks because it is already hold by anotherThread. Both threads are blocked waiting for each other to release the locks. Both threads are blocked without hope to progress.
I am mighty! And this is a mighty small ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic