7stud has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

How can I use threads with perl?

$ perl -v This is perl, v5.10.1 (*) built for darwin-2level Copyright 1987-2009, Larry Wall

====

$ perl -V Summary of my perl5 (revision 5 version 10 subversion 1) configuration +: Platform: osname=darwin, osvers=8.11.1, archname=darwin-2level uname='darwin cws-computer.local 8.11.1 darwin kernel version 8.11 +.1: wed oct 10 18:23:28 pdt 2007; root:xnu-792.25.20~1release_i386 i3 +86 i386 ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno- +strict-aliasing -pipe -I/usr/local/include', optimize='-O3', cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precom +p -fno-strict-aliasing -pipe -I/usr/local/include' ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5370)' +, gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local +/lib' libpth=/usr/local/lib /usr/lib libs=-ldbm -ldl -lm -lc perllibs=-ldl -lm -lc libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libp +erl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/u +sr/local/lib' Characteristics of this binary (from libperl): Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO Built under darwin Compiled at Nov 5 2009 01:43:02 @INC: /usr/local/lib/perl5/5.10.1/darwin-2level /usr/local/lib/perl5/5.10.1 /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level /usr/local/lib/perl5/site_perl/5.10.1 /usr/local/lib/perl5/site_perl/5.8.6 /usr/local/lib/perl5/site_perl .

===

use strict; use warnings; use 5.010; use Config; $Config{useithreads} or die('Recompile Perl with threads to run this p +rogram.'); --output:-- Recompile Perl with threads to run this program. at 3perl.pl line 6.

How do I do that?

Thanks

Replies are listed 'Best First'.
Re: where are my ithreads?
by JavaFan (Canon) on Nov 23, 2009 at 17:15 UTC
    1. Download the source.
    2. Unpack it.
    3. Go to the newly created directory.
    4. Run ./Configure
    5. Answer all the questions. Answer the thread related questions appropriately.
    6. Run make.
    7. Run make test.
    8. Run make install.
      ... or if you're too lazy to answer all these questions, replace steps 4 and 5 with
      sh Configure -de -Dusethreads

      Which usually works on fairly "normal" systems (like most modern Linux distributions)

Re: where are my ithreads?
by ikegami (Patriarch) on Nov 23, 2009 at 18:18 UTC
    Supporting threads imposes a (supposedly 10%) performance penalty on Perl (even when threads aren't being used). As such, supporting them is optional. Your build of Perl was compiled without support. You need to build Perl with thread support. The earlier posts are instructions on how to do so.
Re: where are my ithreads?
by 7stud (Deacon) on Nov 23, 2009 at 22:01 UTC
    Ok. Thanks.
Re: where are my ithreads?
by 7stud (Deacon) on Nov 24, 2009 at 03:11 UTC

    It didn't work. Everything seemed to install correctly:

    $ sh Configure -de -Dusethreads .... .... Updating GNUmakefile... Now you must run 'make'. If you compile perl5 on a different machine or from a different object directory, copy the Policy.sh file from this object directory to the new one before you run Configure -- this will help you with most of the policy defaults. $ make ... ... CCCMD = cc -c -fno-common -DPERL_DARWIN -no-cpp-precomp - fno-strict-aliasing -pipe -I/usr/local/include -O3 cc -o a2p -L/usr/local/lib hash.o str.o util.o walk.o a2p.o -ldl -lm +-lc Everything is up to date. Type 'make test' to run test suite. $ make test ... ... All tests successful. u=3.32 s=3.11 cu=351.85 cs=77.27 scripts=1611 tests=226809 $ sudo make install ... ... /usr/local/share/man/man1/cpanp.1 /usr/local/share/man/man1/cpan2dist.1 /usr/local/share/man/man1/shasum.1 /usr/local/share/man/man1/splain.1 /usr/local/share/man/man1/xsubpp.1 /usr/local/share/man/man1/a2p.1 /usr/local/share/man/man1/find2perl.1 /usr/local/share/man/man1/s2p.1 /usr/local/share/man/man1/psed.1 $

    But, I get the same results:

    $ cat 3perl.pl use strict; use warnings; use 5.010; use Config; $Config{useithreads} or die('Recompile Perl with threads to run this p +rogram.'); $ perl 3perl.pl Recompile Perl with threads to run this program. at 3perl.pl line 6.

    Do ithreads work on macs?

      You appear to be executing the old Perl.
      Just use threads; , since threads knows to die without useithreads.