On Sat, Jun 1, 2013 at 4:17 AM, Cedric Blancher
<[email protected]> wrote:
> I've tried to use the realtime signals in ast-ksh 20130524 to see if
> they are reliable how but ran into instabilities again.
> My example I used for testing is this one:
> ------------cut--------------
[snip]
Attached (as "shrttest2_20130605.sh.txt") is an updated version of
Cedric's test based on feedback...
... main differences:
- The test now validates the _contents_ of the resulting array
- SIGRTMIN up to SIGRTMIN+7 are now used to spread out the testing
through multiple realtime signal channels in the attempt to weed-out
any race conditions by having them arrive in a more or less random
order
ToDo:
- In the future both the main shell code and the trap code should work
on the same array in parallel
- The array should sit in a deeply nested compound variable tree
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
compound -a rtar
function rttrap
{
integer v=${.sh.sig.value}
integer s=${#rtar[v][@]}
integer rtnum=$1
rtar[$v][$s]=(
integer pid=${.sh.sig.pid}
integer rtnum=$rtnum
typeset msg=${v}
)
return 0
}
# POSIX gurantees at least 8 realtime signals
trap 'rttrap 0' RTMIN
trap 'rttrap 1' RTMIN+1
trap 'rttrap 2' RTMIN+2
trap 'rttrap 3' RTMIN+3
trap 'rttrap 4' RTMIN+4
trap 'rttrap 5' RTMIN+5
trap 'rttrap 6' RTMIN+6
trap 'rttrap 7' RTMIN+7
typeset m # used in child processes
integer pid p i
# note that "numchildren" can't be higher than 4*$(ulimit -i)
integer -r numchildren=64
(( pid=$$ ))
for (( p=0 ; p < numchildren ; p++ )) ; do
{
# sleep for a moment to make sure the
# other child processes can become ready
# (sort of "poor man's" "barrier")
sleep 2
for m in 'a' 'b' 'c' 'd' 'e' 'f' ; do
kill -q $((16#$m)) -s RTMIN+6 $pid
kill -q $((16#$m)) -s RTMIN+7 $pid
kill -q $((16#$m)) -s RTMIN+4 $pid
kill -q $((16#$m)) -s RTMIN+5 $pid
kill -q $((16#$m)) -s RTMIN+2 $pid
kill -q $((16#$m)) -s RTMIN+3 $pid
kill -q $((16#$m)) -s RTMIN $pid
kill -q $((16#$m)) -s RTMIN+1 $pid
done
exit 0
} &
done
# wait for children to terminate
# we need to loop here since wait(1) may be aborted
# by signals
while ! wait ; do
true
done
# hack: force signal queue processing
true | read dummy
# hack: force sigchld processing
jobs -l >'/dev/null'
#
# validate results...
#
bool fail=false
if ! (( ${#rtar[@]} == 6 )) ; then
printf 'got {#rtar[@]}=%d, expected 6\n' ${#rtar[@]}
(( fail=true ))
fi
for (( i=0xa ; i <= 0xf; i++ )) ; do
if ! (( ${#rtar[$i][*]} == (numchildren*8) )) ; then
printf 'got {#rtar[%d][*]}=%d,' \
$i ${#rtar[$i][*]}
printf 'expected %d\n' $((numchildren*8))
(( fail=true ))
fi
done
for i in ${!rtar[@]} ; do
for j in ${!rtar[$i][@]} ; do
if [[ ! -v rtar[$i][$j].pid ]] ; then
printf 'variable %q missing.\n' \
"rtar[$i][$j].pid"
(( fail=true ))
fi
if [[ ! -v rtar[$i][$j].rtnum ]] ; then
printf 'variable %q missing.\n' \
"rtar[$i][$j].rtnum"
(( fail=true ))
fi
if [[ ! -v rtar[$i][$j].msg ]] ; then
printf 'variable %q missing.\n' \
"rtar[$i][$j].msg"
(( fail=true ))
elif [[ ! "${rtar[$i][$j].msg-}" == "$i" ]] ; then
printf 'variable %q value %q != %q.\n' \
"rtar[$i][$j].msg" \
"${rtar[$i][$j].msg-}" \
"${i}"
(( fail=true ))
fi
done
done
#(( fail )) && print -v rtar
print '#DONE.'
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers