Documente Academic
Documente Profesional
Documente Cultură
2
3
4
5
6
7
Hardware solution for Synchronization
8
Uninterruptable Instructions to Fetch
and Update Memory
9
What is the Synchronization problem?
lw $t0,balance lw $t2,balance
lw $t1,amount lw $t3,amount
add $t0,$t0,t1 sub $t2,$t2,$t3
sw $t0,balance sw $t2,balance
10
while (TRUE)
{
entry_section ();
critical_section ();
exit_section ();
remainder_section ();
} 11
ATTEMPT 1 – STRICT ALTERNATION
Process P0 Process P1
Two problems:
Satisfies mutual exclusion, but not progress
(works only when both processes strictly alternate)
Busy waiting
12
ATTEMPT 2 – WARNING FLAGS
Process P0 Process P1
shared int flag[2]; shared int flag[2];
while (TRUE) while (TRUE)
{ {
flag[0] = TRUE; flag[1] = TRUE;
while (flag[1]); while (flag[0]);
critical_section(); critical_section();
flag[0] = FALSE; flag[1] = FALSE;
remainder_section(); remainder_section();
} }
Satisfies mutual exclusion
◦ P0 in critical section: flag[0]!flag[1]
◦ P1 in critical section: !flag[0]flag[1]
However, contains a deadlock (both flags may be set to
TRUE !!) 13
(combining warning flags and alternation)
Process P0 Process P1
shared int flag[2]; shared int flag[2];
shared int turn; shared int turn;
while (TRUE) while (TRUE)
{ {
flag[0] = TRUE; flag[1] = TRUE;
turn = 0; turn = 1;
while (turn==0&&flag[1]); while (turn==1&&flag[0]);
critical_section(); critical_section();
flag[0] = FALSE; flag[1] = FALSE;
remainder_section(); remainder_section();
} }
Highly accurate
15
APPLICATIONS
Encryption systems usually require some synchronization
mechanism to ensure that the receiving cipher is decoding
the right bits at the right time.
16
Conclusion
17
18