develooper Front page | perl.perl5.porters | Postings from February 2004

[perl #26969] rand seems to fail w/fork on smp/ht platform

February 21, 2004 13:46
[perl #26969] rand seems to fail w/fork on smp/ht platform
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #26969]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.34 running under perl v5.8.3.

[Please enter your report here]

The last fork test (in t/op/fork.t) randomly fails due to the rand function returning the same value
for both the parent and child on a hyperthreading cpu. (The actual platform used is a dual-processor
capable MB with a single Xeon 2.4 CPU with hyperthreading installed.  Plain vanilla Linux 2.4.25
kernel is compiled with smp/hyperthreading support.)  Using the modified code from below, it appears
the parent and child both have different PIDs, just the rand function returns the same value for
both much too often.  Perhaps rand is not smp/ht compatible?

Reproduce code follows:

pipe(RDR,WTR) or die $!;
my $pid = fork;
die "fork: $!" if !defined $pid;
if ($pid == 0) {
    my $rand_child = rand;
    close RDR;
    print WTR $rand_child, "\n";
    print WTR $$, "\n";
    close WTR;
} else {
    my $rand_parent = rand;
    close WTR;
    chomp(my $rand_child  = <RDR>);
    chomp(my $child_pid  = <RDR>);
    close RDR;

    if ($rand_child ne $rand_parent) {
      print "1\n";
    } else {
      print "FAILED!\n";
    print "parent_pid = $$  child_pid = $pid  (child says: $child_pid)\n";
    print "rand_child = $rand_child    rand_parent = $rand_parent\n";

Actual Result:

Random failure / success due to rand returning same value:

  Example failure:
  parent_pid = 10964  child_pid = 10965  (child says: 10965)
  rand_child = 0.308522486900077553    rand_parent = 0.308522486900077553

  Example success:
  parent_pid = 10966  child_pid = 10967  (child says: 10967)
  rand_child = 0.196727666611881347    rand_parent = 0.312272697760821671

Expected Result:

Success every time...

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

Configured by brad at Thu Feb 19 19:11:37 CST 2004.

Summary of my perl5 (revision 5.0 version 8 subversion 3) configuration:
    osname=linux, osvers=2.4.25, archname=i686-linux-64int-ld
    uname='linux 2.4.25 #8 smp fri feb 20 01:23:42 cst 2004 i686 i686 i386 gnulinux '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=define
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    cppflags='-fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.3/i686-linux-64int-ld/CORE'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.8.3:

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