Task 6

[ Class Overview ]

Task 6: Events and Synchronization

Learning objectives

Task description

OOStuBS should now be extended by synchronization objects, with which threads can inform each other about various events or "wait" for events. The following synchronization objects should be created in this task:

To achieve this, the Waitingroom, Semaphore, Customer, Organizer, Bell, Bellringer, Buzzer, Guarded_Buzzer, Guarded_Organizer, Guarded_Semaphore and Guarded_Keyboard classes must be implemented, the Keyboard class must be extended and the Scheduler, Thread and Watch classes must be adapted.

The 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, the classes Waitingroom, Semaphore, Customer, Organizer, Guarded_Organizer and Guarded_Semaphore must be implemented first. In addition, a small adjustment to Thread is necessary. With the help of 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. Through this, processes block when reading from the keyboard using a semaphore if no 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, the classes Bell and Bellringer can be implemented and tested. A global instance bellringer should be created from Bellringer. If it is clear that especially bellringer works as it should, you can create the 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 the previous tasks, this is now an intended situation that you should handle by making adjustments in the Scheduler.

Templates

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