www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20028] New: Stalled thread in concurrency.d unittest

https://issues.dlang.org/show_bug.cgi?id=20028

          Issue ID: 20028
           Summary: Stalled thread in concurrency.d unittest
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: zorael gmail.com

2.087.

In a unit test in concurrency.d, a thread is spawned to await the numbers 1 to
9 to be sent to it via concurrency messages. A Generator is set up to provide
the numbers, but it only yields 1, 2 and 3. The thread is left waiting for 4 to
9, which never arrive, and the thread stalls on receiveOnly!int().

https://github.com/dlang/phobos/blob/98c7f5aa/std/concurrency.d#L1771

 auto tid = spawn({
     int i;
 
     try
     {
         for (i = 1; i < 10; i++)  // <--
         {
             assertNotThrown!AssertError(assert(receiveOnly!int() == i));
         }
     }
     catch (OwnerTerminated e)
     {
 
     }
 
     // i will advance 1 past the last value expected
     assert(i == 4);
 });
 
 auto r = new Generator!int({
     assertThrown!Exception(yield(2.0));
     yield(); // ensure this is a no-op
     yield(1);
     yield(); // also once something has been yielded
     yield(2);
     yield(3);
 });
 
 foreach (e; r)
 {
     tid.send(e);
 }
Changing it to (i = 1; i <= 3; i++) fixes it and lets the thread exit. --
Jul 04 2019