Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking mechanism. What if a Thread dies?

 
Peter P. Fischer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I've been working for a while in the locking mechanism on the B&S assignment. It's been interesting to read some others points of view regarding the possible solutions. However I have a question about a "dead Thread" (perhaps I haven't look at the forums deeply).

Suppose a simple example where two threads (T1 and T2) are trying to access a lock for writing. Let's say that T1 gets the lock, thus T2 must wait until T1 releases that lock. However T1 dies (what I mean with "dies" is that T1 does not finalize correctly). In this case T2 won't ever get the lock. So which are the possible solutions?

I've been thinking on three possible solutions:
(A) - The use of a WeakReference (as I've read in some books), thus letting the garbage collector to cope with dead threads. Although I think this is the most elegant solution, unfortunately I haven't found a simple solution in my particular case.
(B) - Use some kind of TIME_STAMP to check if the time since the lock has been taken falls within this interval, otherwise assume that the thread holding the lock has died.
(C) - State and discuss in the documentation that although you can have the problem discussed above, the solution is out of the scope of the assignment.

Any comments and solutions will be very welcome.
Thanks,
 
sumuhan umamaheswarampillai
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think choice C is fine. That's what I did
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic