Last change
on this file since 11 was 2, checked in by Mattia Monga, 14 years ago |
Importazione sorgenti
|
-
Property svn:executable
set to
*
|
File size:
533 bytes
|
Rev | Line | |
---|
[2] | 1 | N=2
|
---|
| 2 |
|
---|
| 3 | function assegna(){
|
---|
| 4 | echo $2 >> $1
|
---|
| 5 | }
|
---|
| 6 |
|
---|
| 7 | function leggi(){
|
---|
| 8 | tail -1 $1
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | echo "1">alternanza
|
---|
| 13 |
|
---|
| 14 | TMP=$(mktemp semafori.sh.XXXXXX)
|
---|
| 15 | trap "rm -f $TMP* 2>/dev/null" 0
|
---|
| 16 | rm $TMP
|
---|
| 17 |
|
---|
| 18 | function 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 |
|
---|
| 36 | p 1 &
|
---|
| 37 | p 2 &
|
---|
| 38 |
|
---|
| 39 | wait %1 %2
|
---|
Note:
See
TracBrowser
for help on using the repository browser.