Lets talk about fibers

Dan Olson via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 4 08:54:21 PDT 2015


Dmitry Olshansky <dmitry.olsh at gmail.com> writes:

> On 03-Jun-2015 21:34, Liran Zvibel wrote:
>> Hi,
>>
> [snip]
>
>> There are two main reasons why it does not make sense to move fibers
>> between threads:
>>
>
> For me language being TLS by default is enough to not even try this
> madness. If we allow moves a typical fiber will see different
> "globals" depending on where it is scheduled next.

Opposite problem too, with LLVM's TLS optimizations, the Fiber may keep
accessing same "global" even when yield() resumes on a different thread.

int someTls;      // optimizer caches address 

    auto fib = new Fiber({

        for (;;)
        {
            printf("%d fiber before yield\n", someTls);
            ++someTls;       // thread A's var
            Fiber.yield();
            ++someTls;       // resumed thread B, but still A's var
            printf("%d fiber after yield\n", someTls);
        }
    });


More information about the Digitalmars-d mailing list