Thread overview
[Issue 6116] New: May not join spawn()'ed threads
Jun 06, 2011
Ali Cehreli
Jun 06, 2011
Ali Cehreli
Jul 27, 2011
Sean Kelly
Apr 24, 2012
SomeDude
Apr 24, 2012
Ali Cehreli
June 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6116

           Summary: May not join spawn()'ed threads
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: acehreli@yahoo.com


--- Comment #0 from Ali Cehreli <acehreli@yahoo.com> 2011-06-06 16:33:09 PDT ---
Version: 2.053

The command line:

~/dmd2.053/linux/bin64/dmd deneme.d  -ofdeneme  -unittest -J. -w

Although I have multiple threads spawning each other here, I also had problems with just a single thread spawned from main. I wanted to keep this example as it exposes many different outputs for me.

import std.stdio;
import std.concurrency;
import core.thread;

void foo()
{
    foreach (i; 0 .. 5) {
        Thread.sleep(dur!"msecs"(500));
        writeln(i, " foo");
    }
}

void intermediate3()
{
    spawn(&foo);
    writeln("intermediate3 done");
}

void intermediate2()
{
    spawn(&intermediate3);
    writeln("intermediate2 done");
}

void intermediate()
{
    spawn(&intermediate2);
    writeln("intermediate done");
}

void main()
{
    spawn(&intermediate);
    writeln("main done");
}

1) ThreadException:

$ time ./deneme
main done
intermediate done
intermediate2 done
intermediate3 done
core.thread.ThreadException@src/core/thread.d(866): Unable to join thread
----------------
----------------

real    0m0.003s
user    0m0.000s
sys    0m0.000s

2) No output from foo() (foo() is not joined)

$ time ./deneme
main done
intermediate done
intermediate2 done
intermediate3 done

real    0m0.003s
user    0m0.000s
sys    0m0.000s

3) Segmentation fault:

$ time ./deneme
main done
intermediate done
Segmentation fault

real    0m0.003s
user    0m0.000s
sys    0m0.000s

4) Expected behavior:

$ time ./deneme
main done
intermediate done
intermediate2 done
intermediate3 done
0 foo
1 foo
2 foo
3 foo
4 foo

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6116



--- Comment #1 from Ali Cehreli <acehreli@yahoo.com> 2011-06-06 16:38:06 PDT ---
Apparently I clipped the timings for the last run. When it joins successfully, the program takes long, seemingly waiting for the foo() thread:

$ time ./deneme
main done
intermediate done
intermediate2 done
intermediate3 done
0 foo
1 foo
2 foo
3 foo
4 foo

real    0m2.504s
user    0m0.000s
sys    0m0.000s

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6116


Sean Kelly <sean@invisibleduck.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |sean@invisibleduck.org


--- Comment #2 from Sean Kelly <sean@invisibleduck.org> 2011-07-26 22:53:47 PDT ---
What's likely happening is that the app is terminating before the new threads actually start, so they aren't marked isRunning when the wait loop occurs.  The fix for this will likely be to add a status field where a thread may be marked as ready, starting, running, and terminated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6116


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #3 from SomeDude <lovelydear@mailmetrash.com> 2012-04-24 00:49:12 PDT ---
Run with 2.059 Win32:

PS E:\DigitalMars\dmd2\samples> rdmd bug
main done
intermediate done
intermediate2 done
intermediate3 done
0 foo
1 foo
2 foo
3 foo
4 foo
PS E:\DigitalMars\dmd2\samples>

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6116



--- Comment #4 from Ali Cehreli <acehreli@yahoo.com> 2012-04-24 06:29:21 PDT ---
Same here: This bug seems to have been fixed by other changes.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6116


Alex Rønne Petersen <alex@lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |alex@lycus.org
         Resolution|                            |FIXED


--- Comment #5 from Alex Rønne Petersen <alex@lycus.org> 2012-10-19 09:31:01 CEST ---
Closing this then. Please reopen if the bug resurfaces.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------