On Thu, Jun 6, 2013 at 12:44 AM, Roland Mainz <[email protected]> wrote:
> 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

Attached (as "shrttest2_20130609.sh.txt") is an updated version of the
test. Main difference is that the workaround for
http://lists.research.att.com/pipermail/ast-developers/2013q2/002655.html
("[ast-developers] $ while ! wait ; do true ; done # doesn't wait for
all child processes...",  e.g. I added a $ /usr/bin/true after the
while ! wait ; do true ; done #-loop to aid debugging) has been
applied and that the first dimension size of "rtar" is kept in a
seperate variable called "rtar_i2" to avoid a race condition with
signal handlers from different signals (thanks to Cedric for pointing
this out)

----

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 -S -a rtar_i2 # number of array elements in rtar[v]

        integer v=${.sh.sig.value}
        integer s=$(( rtar_i2[$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 j
# 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

# workaround the issue that "jobs -l" may not reflect the real
# up-to-date status of the child processes
# (see 
http://lists.research.att.com/pipermail/ast-developers/2013q2/002655.html)
# we do this here to avoid any possible intererence from other
# job-related bugs
/usr/bin/true

# hack: force signal queue processing
true | read dummy



#
# 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

Reply via email to