develooper Front page | perl.perl5.porters | Postings from December 2001

[ID 20011229.001] hang forever race condition in ext/Time/HiRes/HiRes.t

Nicholas Clark
December 29, 2001 08:40
[ID 20011229.001] hang forever race condition in ext/Time/HiRes/HiRes.t
Message ID:
This is a build failure report for perl from,
generated with the help of perlbug 1.33 running under perl v5.7.2.

[Please enter your report here]

I have been seeing this off and on for a while on ARM Linux and assumed it
was some oddity about my machine. However, I've booted up my FreeBSD box, and

ext/Time/HiRes/HiRes................FAILED at test 12

It's this test:

    my $tick = 0;
    local $SIG{ALRM} = sub { $tick++ };

    my $one = time; $tick = 0; ualarm(10_000); sleep until $tick;
    my $two = time; $tick = 0; ualarm(10_000); sleep until $tick;
    my $three = time;
    ok 12, $one == $two || $two == $three, "slept too long, $one $two $three";

and I did manage to get a stack backtrace by attaching gdb, but on detaching
to re-attach from t (and get the shared libraries) I must have sent a signal
and the pause(2) returned. Trace is:

.../lib/auto/Time/HiRes/ No such file or directory.
(gdb) where
#0  0x281b6c94 in ?? () from /usr/lib/
#1  0x2819aba6 in ?? () from /usr/lib/
#2  0x2819afca in ?? () from /usr/lib/
#3  0x28185caf in ?? () from /usr/lib/
#4  0x281841a8 in ?? () from /usr/lib/
#5  0x2817a9da in ?? () from /usr/lib/
#6  0x2815e8c6 in ?? () from /usr/lib/
#7  0x80d80c3 in Perl_pp_sleep ()
#8  0x80a22b5 in Perl_runops_standard ()
#9  0x8060d35 in S_run_body ()
#10 0x8060a14 in perl_run ()
#11 0x805dcbe in main ()
#12 0x805dbc5 in _start ()
(gdb) The program is running.  Quit anyway (and detach it)? (y or n) y

However, I conclude that there is a RACE CONDITION in that test.
And my nice slow K5 133 lost the race. I believe that the race is lost if
the ualarm fires between the until $tick; test and the pause() syscall made
by pp_sleep.

Would it work to change the test to:

    my $one = time; $tick = 0; ualarm(10_000); sleep 3 until $tick;
    my $two = time; $tick = 0; ualarm(10_000); sleep 3 until $tick;

[not tested] so that it will fail rather than hanging forever if the race is
lost? Or does this make nasty sleep()/SIGALRM interactions, which pause()
doesn't have?
[another alternative would be to fork a child that sets an alarm and kills
its parent after <long time> (eg 120 seconds)]

Nicholas Clark

[Please do not change anything below this line]
Site configuration information for perl v5.7.2:

Configured by nick at Wed Jan  1 00:46:43 GMT 1997.

Summary of my perl5 (revision 5.0 version 7 subversion 2 patch 13919) configuration:
    osname=freebsd, osvers=4.0-release, archname=i386-freebsd-thread-multi
    uname='freebsd thinking-cap.moo 4.0-release freebsd 4.0-release #0: mon mar 20 22:50:22 gmt 2000 i386 '
    config_args='-Dusedevel -Ubincompat5005 -Uinstallusrbinperl -Dinc_version_list=  -Dinc_version_list_init=0 -Uuse64bitint -e'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include',
    cppflags='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-pthread -Wl,-E  -L/usr/local/lib'
    libpth=/usr/lib /usr/local/lib
    libs=-lm -lc_r -lcrypt -lutil
    perllibs=-lm -lc_r -lcrypt -lutil
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-DPIC -fpic', lddlflags='-shared  -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.7.2:

Environment for perl v5.7.2:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About