You rewrite the WaitOne and Release methods of the Semaphore Class so that five threads enter the Critical area at the same time. You just write the methods. You can use the Interlocked class. It is forbidden to use Lock, Monitor, and Mutex.
Added by Laura J.
Your feedback will help us improve your experience
Madhur L and 79 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
All processes share a semaphore variable mutex, initialized to 1. Each process must execute wait(mutex) before entering the critical section and signal(mutex) afterward. Suppose a process executes in the following manner: signal(mutex), critical section wait(mutex), In this situation: a deadlock will occur processes will starve to enter the critical section several processes may be executing in their critical section all of the mentioned
Madhur L.
It is found that a program has multiple critical sections. Choose correct statements from below: (i) Multiple semaphores are needed for handling the situation. (ii) A single semaphore that uncompresses all the critical section is sufficient and is also more efficient. (iii) To get better control of the code, monitors need to be implemented. (A) (i) and (ii) (B) (ii) and (iii) (C) (i) and (iii) (D) (i), (ii), (iii)
OPERATING SYSTEM
INTERPROCESS COMMUNICATION, CONCURRENCY AND SYNCHRONIZATION
Multithread/Queue Implementation in Java: Synchronized Queue Class Implement a Queue class in Java with synchronized add and remove methods. Provide two threads, a producer and a consumer, to interact with the queue. The producer thread should continuously insert strings into the queue as long as there are fewer than ten elements in it. The strings can be generated using time stamps from the new Date().toString() method. When the queue becomes full, the producer thread should wait. The consumer thread should continuously remove and print strings from the queue as long as the queue is not empty. When the queue becomes empty, the consumer thread should wait. Both the consumer and producer threads should run for 100 iterations. Starter codes are provided. (20 marks)
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD