D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17127 - bad example code for std.concurrency.Generator
Summary: bad example code for std.concurrency.Generator
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2017-01-30 11:17 UTC by ag0aep6g
Modified: 2018-04-19 12:20 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2017-01-30 11:17:07 UTC
Found by Profile Anaysis who posted to D.learn:
http://forum.dlang.org/post/vlvqmzrfvqmxzsfxpslu@forum.dlang.org

The example code for std.concurrency.Generator [1] throws an OwnerTerminated exception. The code:

----
import std.concurrency;
import std.stdio;


void main()
{
    auto tid = spawn(
    {
        while (true)
        {
            writeln(receiveOnly!int());
        }
    });

    auto r = new Generator!int(
    {
        foreach (i; 1 .. 10)
            yield(i);
    });

    foreach (e; r)
    {
        tid.send(e);
    }
}
----

The exception gets thrown because the spawned thread still tries to receive ints after the main thread has finished. The example code should be fixed.


[1] https://dlang.org/library/std/concurrency/generator.html
Comment 2 github-bugzilla 2017-11-21 17:38:11 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/5df663ead1203dea2fd7cbaae189bae99c1eafec
Issue 17127 - bad example code for std.concurrency.Generator

https://github.com/dlang/phobos/commit/a7953301bcbbb416cfcf2d35d3c1647e99a82ee9
Merge pull request #5872 from wilzbach/std-concurrency-tests-1

Issue 17127 - bad example code for std.concurrency.Generator
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
Comment 3 github-bugzilla 2017-11-21 20:19:33 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/d2e716b20ed571ac00e184cdb84a0c158c5136c9
Issue 17127 - bad example code for std.concurrency.Generator

https://github.com/dlang/phobos/commit/4e197f22630329bc44203b72712cb43020fd710e
Merge pull request #5870 from wilzbach/std-concurrency-tests-2

Issue 17127 - bad example code for std.concurrency.Generator
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
Comment 4 github-bugzilla 2017-12-18 22:57:12 UTC
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/d2e716b20ed571ac00e184cdb84a0c158c5136c9
Issue 17127 - bad example code for std.concurrency.Generator

https://github.com/dlang/phobos/commit/5df663ead1203dea2fd7cbaae189bae99c1eafec
Issue 17127 - bad example code for std.concurrency.Generator

https://github.com/dlang/phobos/commit/a7953301bcbbb416cfcf2d35d3c1647e99a82ee9
Merge pull request #5872 from wilzbach/std-concurrency-tests-1

https://github.com/dlang/phobos/commit/4e197f22630329bc44203b72712cb43020fd710e
Merge pull request #5870 from wilzbach/std-concurrency-tests-2
Comment 5 Seb 2018-03-31 19:30:41 UTC
https://github.com/dlang/phobos/pull/5873 is the only bit left, but that's currently failing on 32-bit testers.
Comment 6 github-bugzilla 2018-04-18 15:00:22 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/903c38d7bb4e6ecad86f75ba444737de91fd8078
Issue 17127 - bad example code for std.concurrency.Generator

https://github.com/dlang/phobos/commit/abba3388dc91b990bd9d208cb1fae3d58e6d5be0
Merge pull request #5873 from wilzbach/std-concurrency-tests-4

Issue 17127 - bad example code for std.concurrency.Generator
merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>