source: trunk/peterson.sh@ 12

Last change on this file since 12 was 2, checked in by Mattia Monga, 14 years ago

Importazione sorgenti

  • Property svn:executable set to *
File size: 641 bytes
Line 
1SHARED_MEM=turno
2echo pippo > $SHARED_MEM
3
4processo(){ # name other
5 for i in $(seq 100); do
6 enter_region $1 $2
7 critical_session $1
8 leave_region $1
9 io
10 done
11}
12critical_session(){
13 for i in 1 2 3; do
14 echo -n $1
15 io
16 done
17 echo .
18}
19
20io(){
21 dd if=/dev/zero of=/dev/null count=1000 2>/dev/null
22}
23
24enter_region() { # process other
25 echo "true" > interested_$1
26 echo $1 > $SHARED_MEM
27 while grep $1 $SHARED_MEM >/dev/null &&
28 grep true interested_$2 >/dev/null ;
29 do
30 true;
31 done
32}
33leave_region() { # process
34 echo "false" > interested_$1
35}
36
37processo pippo pluto & processo pluto pippo &
38wait
Note: See TracBrowser for help on using the repository browser.