aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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?


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to determine the number of semaphores by looking at the code?
 
Similar Threads
Can i set the no of threads per servlet in web.xml?
Gettting read or write tokens in LockManager - any savings ?
Concurrency Utilities
Inheritance problem
Question on Semaphores