Embed presentation
Downloaded 25 times

![Solución para 2 procesos (Peterson - 1981) Shared variables of algorithms 1 and 2 - initialization: int flag[2]; flag[0] = flag[1] = 0; int turn = 0; Thread T i do { flag[i] = 1; turn = j; while ((flag[j] == 1) && turn == j) ; critical section flag[i] = 0; remainder section } while (1); Solves the critical-section problem for two threads.](https://image.slidesharecdn.com/mssobrepeterson-111129002012-phpapp02/85/Mas-sobre-el-Algoritmo-de-Peterson-2-320.jpg)
![Solución para N procesos (Hofri - 1990) N procesos, T 1 a T N-1 , N niveles/salas de espera: int level[n]; int turn[n-1]; // primer proceso=1 Thread T i do { for (k = 1 ; k < n ; k++) { level[i] = k; turn[k] = i; foreach (t != i) if (level[t] >= k && turn[k] == i) ; } level[i] = n; critical section level[i] = 0; remainder section } while (1);](https://image.slidesharecdn.com/mssobrepeterson-111129002012-phpapp02/85/Mas-sobre-el-Algoritmo-de-Peterson-3-320.jpg)

The document discusses two algorithms for solving the critical section problem for multiple processes: 1. Peterson's algorithm from 1981 solves the problem for two processes using shared variables like flags and a turn variable to ensure only one process enters the critical section at a time. 2. Hofri's algorithm from 1990 generalizes the solution to N processes using an array of level variables and a turn array to designate the next process that can enter. Each process must pass through N "waiting rooms" represented by the increasing level values before entering the critical section.

![Solución para 2 procesos (Peterson - 1981) Shared variables of algorithms 1 and 2 - initialization: int flag[2]; flag[0] = flag[1] = 0; int turn = 0; Thread T i do { flag[i] = 1; turn = j; while ((flag[j] == 1) && turn == j) ; critical section flag[i] = 0; remainder section } while (1); Solves the critical-section problem for two threads.](https://image.slidesharecdn.com/mssobrepeterson-111129002012-phpapp02/85/Mas-sobre-el-Algoritmo-de-Peterson-2-320.jpg)
![Solución para N procesos (Hofri - 1990) N procesos, T 1 a T N-1 , N niveles/salas de espera: int level[n]; int turn[n-1]; // primer proceso=1 Thread T i do { for (k = 1 ; k < n ; k++) { level[i] = k; turn[k] = i; foreach (t != i) if (level[t] >= k && turn[k] == i) ; } level[i] = n; critical section level[i] = 0; remainder section } while (1);](https://image.slidesharecdn.com/mssobrepeterson-111129002012-phpapp02/85/Mas-sobre-el-Algoritmo-de-Peterson-3-320.jpg)