wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes How to determine the number of semaphores by looking at the code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How to determine the number of semaphores by looking at the code?" Watch "How to determine the number of semaphores by looking at the code?" New topic
Author

How to determine the number of semaphores by looking at the code?

azuki ooh
Greenhorn

Joined: Nov 07, 2008
Posts: 20
The following program (ReaderOrWriter class) that implements the readers-writers problem with semaphores.

The main program (not shown) creates many reader and writer threads, starts each of them, and then waits forever for them to terminate by calling each thread’s join() method.



What values should each of the semaphores be initialized to?
s: ??
okToRead: ??
okToWriteL ??

How can I tell what is the semaphore value just by looking at the codes?

Assume a reader is currently using the buffer. If there are both waiting writers and waiting readers, will a writer or a reader get access to the buffer first?

Is it possible for readers to starve with this code?

Can the semaphore okToRead have a value greater than 1?

Can the semaphore okToWrite have a value greater than 1?


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to determine the number of semaphores by looking at the code?
 
Similar Threads
Inheritance problem
Question on Semaphores
Gettting read or write tokens in LockManager - any savings ?
Can i set the no of threads per servlet in web.xml?
Concurrency Utilities