Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Locking

 
rohan tiwari
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am done with the coding of my project..URLYBird 1.1.2.It took me 120 hrs approx.
I have a requirement for my lock method which states that:
"If the specified record is already locked by a different
client, the current thread gives up the CPU and consumes no CPU cycles until the record is unlocked".

I have implemented timeout and reentrant locks in my reservation lock manager class . I think that if a thread conditionally waits for a short timeout or until a lock is released (whichever comes earlier) would not consume CPU cycles,since after the timeout the thread gives up as opposed to blocking continously until the lock is released.


Is my understanding correct ?
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should NOT use timeouts based on my understanding from the Monkhouse's book and posts.
Pay attention to the part where it says "by another client" if it is written in the assignment this means that if the client is trying to lock a record that is already locked by itself the client should not wait.
 
rohan tiwari
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..
I have removed timeouts.
 
John R Roberts
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like you my solution used the ReentrantLock and Condition classes, NO timeouts.
I obtained 80/80 in the locking portion of the exam. Sounds like your taking a good approach.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic