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

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

From:
perlbug-followup
Date:
February 21, 2004 13:46
Subject:
[perl #26969] rand seems to fail w/fork on smp/ht platform
Message ID:
rt-3.0.8-26969-79049.2.26766761958821@perl.org
# New Ticket Created by  brad@info-link.net 
# Please include the string:  [perl #26969]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=26969 >



This is a bug report for perl from brad@info-link.net,
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) {
    srand;
    my $rand_child = rand;
    close RDR;
    print WTR $rand_child, "\n";
    print WTR $$, "\n";
    close WTR;
} else {
    srand;
    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:
  ------------------
  FAILED!
  parent_pid = 10964  child_pid = 10965  (child says: 10965)
  rand_child = 0.308522486900077553    rand_parent = 0.308522486900077553

  Example success:
  ------------------
  1
  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]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
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:
  Platform:
    osname=linux, osvers=2.4.25, archname=i686-linux-64int-ld
    uname='linux new-mail.info-link.net 2.4.25 #8 smp fri feb 20 01:23:42 cst 2004 i686 i686 i386 gnulinux '
    config_args=''
    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
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O3',
    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/libc-2.3.2.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.2'
  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:
    /usr/lib/perl5/5.8.3/i686-linux-64int-ld
    /usr/lib/perl5/5.8.3
    /usr/lib/perl5/site_perl/5.8.3/i686-linux-64int-ld
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl
    .

---
Environment for perl v5.8.3:
    HOME=/root
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/home/brad/bin:/sbin:/usr/sbin:/usr/local/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About