Semaphores In this assignment you'll be writing a solution to the problem of reading a piece of memory. The idea is that there are two types of processes that may access the memory. Readers can all access the memory at the same time but not while someone is writing. Writers can access the memory only when there are no other readers or writers. Your job is to write the entry and exit code for both the readers and the writers. Your main job is to ensure that multiple readers can read according to the rules above. Writers must write only when there is nobody writing and nobody reading. For full credit, ensure that neither a reader nor a writer is ever starved. You may assume that the semaphores on this OS use a queue, which helps with some solutions to the critical section problem. Use a random number generator in the critical section to allow processes to sleep. This will simulate their turn, either reading or writing. Here's an example that could work for both the reader and the writer. However, entrance to the critical section for reader and writer follow different rules. In any case, here's one way to make your process sleep in the critical section with the important critical section in the middle. ------------------------------------------------------------ //write your entry section here //begin critical section int x = rand() % 10+1; sleep(x); //sleep for 1-10 seconds //end the critical section //write your exit section here ------------------------------------------------------------ To test your code, you may spawn threads as readers or writers and give simple outputs in the critical section to see how things are working. You can also fork readers or writers in separate programs, although they'll need to attach to any semaphores they may need to share.