Issue 20028 - Stalled thread in concurrency.d unittest
Summary: Stalled thread in concurrency.d unittest
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-04 23:54 UTC by JR
Modified: 2024-12-01 16:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description JR 2019-07-04 23:54:10 UTC
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.
Comment 1 berni44 2019-12-10 10:33:34 UTC
What exactly is the problem? This unittest has run thousends of times and always worked. IMHO the loop intentionally loops until 10. This is part of the test...
Comment 2 dlangBugzillaToGithub 2024-12-01 16:35:10 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10377

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB