This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04.05-Problema_seção_crítica
39 lines (34 loc) · 1.71 KB
/
04.05-Problema_seção_crítica
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Problema da seção crítica
==========================
* Temos 'n' processos que repetidamente executam uma seção de código
crítica (ex: variável compartilhada) e uma seção de código não crítica.
* Podemos descrever os processo, de uma forma alto nível, como:
| process SC[i=1 to n] {
| while(true) {
| protocolo de entrada; # para entrar na seção crítica
| SEÇÃO CRÍTICA; # não pode ter mais de um processo
| # rodando ao mesmo tempo
| protocolo de saída; # para sair da seção crítica
| SEÇÃO NÃO CRÍTICA;
| }
| }
- Poderíamos tentar resolver o problema colocando <> em torno
do protocolo de entrada + SEÇÃO CRÍTICA. Porém, veremos que
essa solução não é suficiente para conseguirmos as propriedades
necessárias para resolver o problema da seção crítica.
* Para uma solução resolver o problema da seção crítica, ela precisa
seguir 4 propriedades:
- Exclusão mútua
- Só um processo entra na região num dado momento.
- Ausência de deadlocks (livelocks)
- Dois processos não ficam esperando por condiçẽos um do outro,
impedindo que ambos rodem.
- Deadlock: processo travado sem fazer nada (esperando algum
recurso que seja de outro processo).
- Livelock: processo travado gastando tempo de CPU (ex: com
busy waiting, parado num <await> implementado com laço).
- Ausência de espera desnecessária
- Não desperdiçaremos tempo para conseguir resolver
o problema de exclusão mútua.
- Entrada garantida
- Todos os processos têm chance de rodar em algum momento.