Task 6

[ Class Overview ]

Task 6: Events and Synchronization

Learning objectives

Task description

In this task, you should extend OOStuBS by synchronization objects, with which threads can inform each other about various events or "wait" for events. You should create the following synchronization objects in this task:

To achieve this, you must implement the classes Waitingroom, Semaphore, Customer, Organizer, Bell, Bellringer, Buzzer, Guarded_Buzzer, Guarded_Organizer, Guarded_Semaphore and Guarded_Keyboard, extend class Keyboard, and adapt classes Scheduler, Thread and Watch.

Class Guarded_Scheduler is no longer needed, since Guarded_Organizer takes over its task. Likewise the global Guarded_Scheduler object scheduler is to be replaced by a global Guarded_Organizer object organizer.

Chain List Bellringer Bell Buzzer Guarded_Buzzer thread object Meeting syscall user device

Implementation

Part a

It is best to start with the implementation of the semaphores. For this purpose, implement classes Waitingroom, Semaphore, Customer, Organizer, Guarded_Organizer and Guarded_Semaphore first. In addition, a small adjustment to Thread is necessary. Using semaphore variables you should now be able to prevent your application processes from interfering with each other during screen output.

Part b

In the next step, you can then extend the Keyboard and Guarded_Keyboard classes with the getkey() method. With this method, processes block when reading from the keyboard until a key has been pressed. Extend your program that one of the processes makes keyboard requests (and reacts to them in some visible way).

Part c

Subsequently, implement and test classes Bell and Bellringer. Create a global instance bellringer from class Bellringer. If it is clear that especially bellringer works as it should, you can create classes Buzzer and Guarded_Buzzer. With this you can easily create periodic processes, where a process goes to sleep for a few milliseconds and then makes an output. You should also prepare a suitable example for this.

Part d

From this point on, it may happen that all applications are waiting for semaphores or buzzers and therefore there are no runnable threads. Unlike in the previous tasks, this is now an intended situation that you should handle by making adjustments in the Scheduler.

Template code

We have already done the implementation of the List class for you.