source: trunk/semafori.sh@ 2

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

Importazione sorgenti

  • Property svn:executable set to *
File size: 533 bytes
RevLine 
[2]1N=2
2
3function assegna(){
4 echo $2 >> $1
5}
6
7function leggi(){
8 tail -1 $1
9}
10
11
12echo "1">alternanza
13
14TMP=$(mktemp semafori.sh.XXXXXX)
15trap "rm -f $TMP* 2>/dev/null" 0
16rm $TMP
17
18function p(){
19 local p
20 for p in $(seq $(( $1 * 10 )) $(( $1 * 10 + 9 )) ); do
21 while true; do
22 lockfile $TMP
23 if [ $(leggi alternanza) -eq $1 ]; then
24 echo $p
25 assegna alternanza "$(( ( $(leggi alternanza) % 2 ) + 1))"
26 rm -f $TMP
27 break
28 else
29 rm -f $TMP
30 fi
31 sleep 0.01
32 done
33 done
34}
35
36p 1 &
37p 2 &
38
39wait %1 %2
Note: See TracBrowser for help on using the repository browser.