SlideServe
Menu
Préférences
© SlideServe · v2026

Coursework 1 : Semaphore Implementation

allie avatar
2 diapositives · 226 Views · Jul 13, 2014

Coursework 1 : Semaphore Implementation Task : To write a package of functions or methods which implement P and V semaphore operations and to emulate their behaviour in an emulated multi-tasking environment. Background Semaphores are to be identified by a string of characters e.g. “mutex”.

Coursework 1 : Semaphore Implementation - slide 1
01 / 2Coursework 1 : Semaphore Implementation
1 / 17

Télécharger la présentation

Coursework 1 : Semaphore Implementation
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Operating Systems : Coursework 1 Coursework 1 : Semaphore Implementation Task : To write a package of functions or methods which implement P and V semaphore operations and to emulate their behaviour in an emulated multi-tasking environment. Background • Semaphores are to be identified by a string of characters e.g. “mutex”. • Processes are to be identified by an ID number within some range e.g. 0-255. Specifications The following functions should be implemented : create_semaphore (string semaphore); P (string semaphore, int process); V (string semaphore); present_status (); In this emulation, no run queue or process scheduling is required. Instead of branching to a dispatcher, messages are printed out monitoring the effect of the operation just performed. The P operation tests the value of the semaphore. If it is free, the process is allocated the semaphore and a message to this effect is printed out. If the semaphore is not free, the process must be queued in some appropriate data structure and a message printed out to that effect. The V operation also tests the semaphore. If there are any processes queued waiting for it, the next one is notionally dispatched and a message is printed out saying this process now has the semaphore. For example, the function calls : create_semaphore (“mutex”); P(“mutex”, 1); P(“mutex”, 2); V(“mutex”); V(“mutex”); should produce output of the form semaphore “mutex” created P(“mutex”, 1) : “mutex” allocated to process 1 P(“mutex”, 2) : process 2 queued on “mutex” V(“mutex”) : “mutex” released by process 1 “mutex” allocated to process 2 V(“mutex”) : “mutex” released by process 2 “mutex” free

  2. Operating Systems : Coursework 1 • The present_status function should print out the current status of all the semaphore queues. For example, after the calls : • P (“fred”, 1); • P(“jim”, 1); • P(“fred”, 2); • P(“fred”, 3); • the status printed should be something like : • “fred” : allocated to process 1 • awaited by process 2 • awaited by process 3 • “jim” : allocated to process 1 • This function should also detect deadlocks. For example, after : • P (“mike”, 1); • P(“roland”, 2); • P(“roland”, 1); • P(“mike”, 2); • the status printed out should be : • “mike” : allocated to process 1 • awaited by process 2 • “roland” : allocated to process 2 • awaited by process 1 • deadlock detected : processes 1, 2 • Notes • Semaphores should initially be free • In practice, any one process cannot be queued awaiting more than one semaphore. A test should be incorporated to preclude this arising by mistake in the emulation requested. • Multiple disjoint deadlock cycles, each of any length, should be detected. • First-Come-First-Served order of queuing for semaphores should be preserved. • Any implementation language desired may be used. • Efficiency may be taken into account when grading submissions. • Hand-in • An annotated listing of your program • Representative tests and the resulting output • Deadline : 5pm, Friday 16th November, to the ITO.