Bug in generator
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 30 03:17:35 PST 2017
On 01/30/2017 11:58 AM, Profile Anaysis wrote:
> the code from https://dlang.org/library/std/concurrency/generator.html
>
> gives a seg fault at the end.
>
> 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);
> }
> }
[...]
I don't see a segfault, but an exception:
"std.concurrency.OwnerTerminated at std/concurrency.d(241): Owner terminated".
Which makes sense because the spawned thread still tries to receive ints
after the main thread has finished. So, the example is bad and should be
fixed. I've filed an issue:
https://issues.dlang.org/show_bug.cgi?id=17127
More information about the Digitalmars-d-learn
mailing list