INE5357 - Operating Systems II - 2006/2

Group 1

E4: system object deletion

Introduction

In this exercise we added the logics for deletion of important objects. This objects include: thread, semaphore, mutex and condition. Also, the remaining changes on the system regarding the idle waiting were also corrected in order to accomplish the given tasks.

Solution

To proper delete a thread, one must pay atention to the queues and states that surround this thread. For instance, what would happen if one delete a thread that is waiting for another one to finish?

To deal with language deletes the only place to look for is the so-called destructor. On the thread, it is implemented on the file thread.h@150. The first counter-measure it is to remove itself from the _ready, _suspended queues. This action cannot result in an error if the thread does not belong into any of these queues (kind of obvious, because it cannot be on both at the same time). The next step it is to check if the thread has another thread waiting for it to finish. If that is the case we set the pointers _awaker->waiting , _awaker to NULL. The same has to be done with the sleeping thread. The final step is to set a -1 value into the return value, to let any other thread interested know the situation that the thread ended up.

To deal with the semaphore, mutex and condition we changed the destructor of the superclass Synchronizer_Commom. All these objects have the same semantic interpretation on deletion. All we did was to add a destructor on file commom/synchronizer@23. The destructor calls wakeup_all() which wakes up all the thread that are related to this synchronizer. We think that this is the best solution.

To correct the idle waiting on the other exercise, we created a new thread (called idle) and inserted on the ready queue. This thread is put into execution everytime a there is no other threads to execute. Idle sits on a endless loop calling CPU::halt() to save some power. The idle thread has the lowest priority on the system. This is done to avoid scheduling.

Table of Files

Changed files
File Comment
thread.h Added some key behaviour to finnish exercise.
thread.cc Added some key behaviour to finnish exercise.
synchronizer.h Created the destructor needed by semaphore, mutex and condition to proper deletion