Sunteți pe pagina 1din 18

1

2
3
4
5
6
7
Hardware solution for Synchronization

8
Uninterruptable Instructions to Fetch
and Update Memory

9
What is the Synchronization problem?

/* Process P_c */ /* Process P_d */


shared int balance shared int balance
private int amount private int amount

balance += amount balance -= amount

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

shared int turn; shared int turn;


while (TRUE) while (TRUE)
{ {
while (turn!=0); while (turn!=1);
critical_section(); critical_section();
turn = 1; turn = 0;
remainder_section(); remainder_section();
} }

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();
} }

• Software solution is slow !


• Difficult to extend to more than 2 processes 14
Efficient use of limited resources

Highly accurate

Dead Lock avoidance

Lower overhead and thus, greater


throughput

15
APPLICATIONS
Encryption systems usually require some synchronization
mechanism to ensure that the receiving cipher is decoding
the right bits at the right time.

A Mobile phone synchronization using SyncML –standards


or java based technology to perform a backup on a phone.

Film synchronization of image and sound in sound film.

In electric power systems, alternator synchronization is


required when mulitple generators are connected to an
electrical grid.

16
Conclusion

Coordination is performed between two process.

Limited resources can be used very efficiently.

17
18

S-ar putea să vă placă și