• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic