• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic