Thread join behaviour

Russel Winder russel at winder.org.uk
Sat Apr 14 09:04:03 PDT 2012


I thought the following would terminate gracefully having printed 0..9
in some (random) order:

        #! /usr/bin/env rdmd
        
        import std.algorithm ;
        import std.range ;
        import std.stdio ;
        import core.thread ;
        
        int main ( immutable string[] args ) {
          auto threads = map ! ( ( int a ) {
              void delegate ( ) f ( ) {
                return delegate ( ) { writeln ( a ) ; } ; 
              }
              return new Thread ( f )  ;
            } ) ( iota ( 10 ) ) ;
          foreach ( t ; threads ) { t.start ( ) ; }
          foreach ( t ; threads ) { t.join ( ) ; }
          return 0 ;
        }

However, this does not happen, at least with 2.059 on Linux as per
Debian Unstable.  Instead I get:

        1
        2
        4
        5
        8
        3
        7
        6
        9
        0
        core.thread.ThreadException at src/core/thread.d(906): Unable to join thread
        ----------------
        /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/initializingWithAMap.d.9532BBED12C814F25F173A9AEAB96D0D(_Dmain+0x83) [0x425edb]
        /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/initializingWithAMap.d.9532BBED12C814F25F173A9AEAB96D0D(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17) [0x429bab]
        /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/initializingWithAMap.d.9532BBED12C814F25F173A9AEAB96D0D(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x23) [0x42952b]
        /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/initializingWithAMap.d.9532BBED12C814F25F173A9AEAB96D0D(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3d) [0x429bf9]
        /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/initializingWithAMap.d.9532BBED12C814F25F173A9AEAB96D0D(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate())+0x23) [0x42952b]
        /tmp/.rdmd-1000/home/users/russel/Progs/OddsByLanguage/D/Odds/initializingWithAMap.d.9532BBED12C814F25F173A9AEAB96D0D(main+0xd3) [0x4294c3]
        /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd) [0x7f1ed17f8ead]
        ----------------

I think I must be having a dumb moment as my reaction continues to be
WTF.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120414/e710ad81/attachment.pgp>


More information about the Digitalmars-d-learn mailing list