develooper Front page | perl.ithreads | Postings from August 2002

Trying to imagine the current (i)threads in larger projects

Thread Previous | Thread Next
From:
Waldemar Rachwal
Date:
August 23, 2002 03:39
Subject:
Trying to imagine the current (i)threads in larger projects
Message ID:
3D652BF2.1F76D827@motorola.com
Below there is a very simple script that does ... in fact nothing.
It spawns 200 dummy threads, then main thread is trying to join all of them.

Unexpectedly the script crashes with Segmentation fault (see log) on my Solaris.
If I add 'next unless defined $thr' just before 'if' clause the warning disappears,
but fatal error remains.

By the way, a few questions arise:
1) Why spawning of 200 threads takes about 10 seconds?
2) Why they occupy 75MB?! I couldn't include (use) less modules ;)

It looks they are related.
New perl with ithreads seems to be the very busy guy, even if it doesn't have much to do.

3) Is it truth that the code from compiled modules is cloned when new thread
is being created?
If so, I doubt anyone at any time will do any nontrivial program with this
implementation of (i)threads. However, I'd want to be wrong.

4) Last but not least. Is there any document being more on design goals
and implementation decisions (what, when and why) than ... hollow words
what ithreads are and what they are not.

Such a paper would be very very useful. Not everyone of perl users
knows perl guts as developers dealing with the perl internals day after day do,
but probably there are quite a lot of programmers who knows threads
sufficiently well that they might help a lot or at least to point potential pitfalls
in this hard subject.

Maybe the current perl has things in its design that make difficult to implement
(i)threads in the right way. I don't know. And I don't know in what stage are (i)threads
in parrot/Perl6...

Thanks,
Waldemar Rachwal

--

> simple_but_crash
Can't call method "tid" on an undefined value at simple_but_crash line 11.
Segmentation fault

------------------------------------------------------------------

  PID USERNAME THR PRI NICE  SIZE   RES STATE   TIME    CPU COMMAND
21998 wrachwal   3   0    0   75M   75M cpu1    0:09  8.81% simple_but_cras

------------------------------------------------------------------

#!/usr/local/bin/perl5.8.0 -w

use threads;

foreach (1 .. 200) {
    threads->new(sub { 1 });
}

foreach my $thr (threads->list) {
    if ($thr->tid and not threads::equal($thr, threads->self)) {
        $thr->join;
    }
}

------------------------------------------------------------------

> perl5.8.0 -V
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris-thread-multi
    uname='sunos btsview 5.6 generic_105181-26 sun4u sparc sunw,ultra-enterprise '
    config_args='-de -Dprefix=/store1/tools/perl/5.8.0 -Dcc=gcc -Uinstallusrbinperl -Dusethreads'
    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
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.6'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc
    perllibs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-E'
    cccdlflags='-fPIC', lddlflags=' -Wl,-E -G -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
  Built under solaris
  Compiled at Jul 25 2002 15:16:32
  @INC:
    /store1/tools/perl/5.8.0/lib/5.8.0/sun4-solaris-thread-multi
    /store1/tools/perl/5.8.0/lib/5.8.0
    /store1/tools/perl/5.8.0/lib/site_perl/5.8.0/sun4-solaris-thread-multi
    /store1/tools/perl/5.8.0/lib/site_perl/5.8.0
    /store1/tools/perl/5.8.0/lib/site_perl
    .

Thread Previous | Thread Next


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