User Tools

Site Tools


Action disabled: source
os:lab09
Return to Home page

Return to Operationg Systems home


Operating Systems Course: Lab09

Laboratory number 09

Exercise 01: Access to critical sections

Suppose to have in substitution of the function test-and-set and of the function swap, the following atomic function:

int atomicIncrement (int *var) {
  int tmp = *var;
  *var = tmp + 1;
  return (tmp);
}

Use this function to write the functions init, lock, and unlock to insert in the reservation code and in the release code of a critical section.

Suggestion:
Use two global variables ticketNumber and turnNumber.
The first indicates the reservation order to enter the critical section, and the second manages the turn for accessing the critical section.
Manage these variables through the functions init, lock, and unlock.

Exercise 02-04: Precedence graphs with semaphores

Given the following precedence graph:

       A  <--------
    /  |  \       ^
   /   |   \      |
  B    C    D     |
  |   / \   |     |
  |  /   \  |     |
  | E    F  |     |
  |  \   /  |     |
  |   \ /   |     |
  |    G    H     |
   \   |   /      |
    \  |  /       |
       I  ---------

in which each vertex corresponds to an independent task (a process or a thread).
Implement it with the following ways, and using the minimum number of semaphores.

Exercise 02

Each task corresponds to a process.
Each process is (re-)created and destroyed at each iteration of the principal cycle.
Semaphores are implemented by means of pipes.

Exercise 03

Each task corresponds to a thread.
Each thread is (re-)created and destroyed at each iteration of the principal cycle.
Semaphores are implemented by means of the POSIX library, and types/functions sem_*.

Exercise 04

Each task corresponds to a thread.
Threads are all cyclic and they are created and destroyed only one time in the principal cycle.
Semaphores are implemented by means of the POSIX library, and types/functions sem_*.


If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/lab09?do=edit
/web/htdocs/www.skenz.it/home/data/pages/os/lab09.txt · Last modified: 2019/12/16 08:09 by zioskenz

Privacy Policy