# New Ticket Created by  Doug Schrag 
# Please include the string:  [perl #129949]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129949 >


This probably is an issue with moarvm.

When trying to benchmark the concurrent and non-concurrent versions of 
Damien Conway's 'bogosort' algorithm, I ran into numerous problems with 
Rakudo Star 2016.07 - depending on the MAX_RAKUDO_THREADS setting, the 
process might succeed, or it might slowly eat up all of memory, and if 
more than a few threads were used only some would actually process 
anything (accumulate CPU time). rakudo-star-2016.10-RC0 looks like it 
solved the deadlock problem, so that all threads are actually working.

However, now this version of the program crashes after the first thread 
completes with:
   Internal error: zeroed target thread ID in work pass

or occasionally:
   Internal error: invalid thread ID 8770096 in GC work pass

Test runs:

doug@ender:~/study/Perl6/benchmarks$ RAKUDO_MAX_THREADS=2 perl6 
bench_bogosort_simple.pl6
[e i l p r s x]
1 seconds.
Internal error: invalid thread ID 8770096 in GC work pass
doug@ender:~/study/Perl6/benchmarks$ RAKUDO_MAX_THREADS=2 perl6 
bench_bogosort_simple.pl6
[e i l p r s x]
4 seconds.
Internal error: zeroed target thread ID in work pass
doug@ender:~/study/Perl6/benchmarks$ RAKUDO_MAX_THREADS=2 perl6 
bench_bogosort_simple.pl6
[e i l p r s x]
24 seconds.
Internal error: zeroed target thread ID in work pass
doug@ender:~/study/Perl6/benchmarks$ RAKUDO_MAX_THREADS=2 perl6 
bench_bogosort_simple.pl6
[e i l p r s x]
6 seconds.
Internal error: zeroed target thread ID in work pass


I also found that the problem is likely related to a channel not being 
explicitly closed, so I was able to get normal test runs as follows:

[ With a LEAVE block to close the channels ]

doug@ender:~/study/Perl6/benchmarks$ RAKUDO_MAX_THREADS=2 perl6 
bench_bogosort_simple.pl6
[e i l p r s x]
4 seconds.
[e i l p r s x]
29 seconds.
[e i l p r s x]
57 seconds.
[e i l p r s x]
58 seconds.
doug@ender:~/study/Perl6/benchmarks$ RAKUDO_MAX_THREADS=2 perl6 
bench_bogosort_simple.pl6
[e i l p r s x]
4 seconds.
[e i l p r s x]
10 seconds.
[e i l p r s x]
20 seconds.
[e i l p r s x]
31 seconds.

I'm figuring that failing to close the channels is bad practice to start, 
but we don't really want to crash the VM with an obscure error message. 
Also, I saw a bug report earlier this year where this message was 
produced, but closed because of uncertainty in reproducing it. This test, 
however fails quite repeatably, at least on my system (linux).

Code file is attached. System report follows.

Doug Schrag <><
aka dmaestro
Houston, TX
Traverse City, MI

Summary of my perl5 (revision 5 version 18 subversion 1) configuration:

   Platform:
     osname=linux, osvers=3.10.9, archname=x86_64-linux-thread-multi
     uname='linux hive64 3.10.9 #1 smp wed aug 21 14:50:51 cdt 2013 x86_64 
amd phenom(tm) ii x6 1100t processor authenticamd gnulinux '
     config_args='-de -Dprefix=/usr -Dsiteprefix=/usr/local 
-Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 
-Darchlib=/usr/lib64/perl5 -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5 
-Dvendorlib=/usr/share/perl5/vendor_perl 
-Dvendorarch=/usr/lib64/perl5/vendor_perl -Dscriptdir=/usr/bin 
-Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dlibpth=/usr/local/lib64 
/usr/lib64 /lib64 -Doptimize=-O2 -fPIC -Dusethreads -Duseithreads 
-Duseshrplib -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr 
-Darchname=x86_64-linux'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=define, usemultiplicity=define
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=define, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing 
-pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64',
     optimize='-O2 -fPIC',
     cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe 
-fstack-protector -I/usr/local/include'
     ccversion='', gccversion='4.8.1', gccosandvers=''
     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -fstack-protector'
     libpth=/usr/local/lib64 /usr/lib64 /lib64
     libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
     perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
     libc=/lib64/libc-2.17.so, so=so, useshrplib=true, libperl=libperl.so
     gnulibc_version='2.17'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E 
-Wl,-rpath,/usr/lib64/perl5/CORE'
     cccdlflags='-fPIC', lddlflags='-shared -O2 -fPIC -fstack-protector'


Characteristics of this binary (from libperl):
   Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
                         PERL_DONT_CREATE_GVSV
                         PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                         PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
                         PERL_PRESERVE_IVUV PERL_SAWAMPERSAND 
USE_64_BIT_ALL
                         USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                         USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                         USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
                         USE_REENTRANT_API
   Built under linux
   Compiled at Sep  2 2013 18:11:30
   %ENV:
     PERL5LIB="/home/doug/perl5/lib/perl5"
     PERLBREW_BASHRC_VERSION="0.72"
     PERLBREW_HOME="/home/doug/.perlbrew"
     PERLBREW_ROOT="/home/doug/perl5/perlbrew"
     PERL_MB_OPT="--install_base "/home/doug/perl5""
     PERL_MM_OPT="INSTALL_BASE=/home/doug/perl5"
     PERL_STRICTURES_EXTRA=""
   @INC:
     /home/doug/perl5/lib/perl5/x86_64-linux-thread-multi
     /home/doug/perl5/lib/perl5
     /usr/local/lib64/perl5
     /usr/local/share/perl5
     /usr/lib64/perl5/vendor_perl
     /usr/share/perl5/vendor_perl
     /usr/lib64/perl5
     /usr/share/perl5
     .
use v6;

sub bogosort_concurrent ( *@list ) {
    my $sorted = Channel.new;

    start until $sorted.closed {
        start {
            my @guess = @list.pick(*);

            $sorted.send( @guess )
                if [!after] @guess;
        }
    }

    return $sorted.receive;
#   Using the LEAVE block prevents the error
#   LEAVE { $sorted.close }
}

my @test_data = < p e r l s i x >;

for ^4
{
    say bogosort_concurrent(@test_data);
    say time - INIT { time }, ' seconds.';
}

Reply via email to