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@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

Reply via email to