User Tools

Site Tools


os:lab08
Return to Home page

Differences

This shows you the differences between two versions of the page.


os:lab08 [2024/04/08 22:35] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +Return to [[os:|Operationg Systems home]]
 +----
 +====== Operating Systems Course: Lab08 ======
 +===== Laboratory number 08 =====
 +
 +
 +==== 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:
 +
 +<code c>
 +int atomicIncrement (int *var) {
 +  int tmp = *var;
 +  *var = tmp + 1;
 +  return (tmp);
 +}
 +</code>
 +
 +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//:
 +
 +<code txt>
 +        <--------
 +    /  |  \       ^
 +   /          |
 +  B    C    D     |
 +  |   / \       |
 +  |  /    |     |
 +  | E    F  |     |
 +  |  \   /  |     |
 +  |   \ /       |
 +  |    G    H     |
 +       /      |
 +    \  |  /       |
 +        ---------
 +</code>
 +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/lab08?rev=1575529002&do=diff

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
Privacy Policy