On Tue, Jan 25, 2022 at 01:31:29AM +0000, Jaime via Digitalmars-d-learn wrote: > **The lede**: > > Can I, for instance, safely call Fiber.yield in a C callback that I > know will be run in a Fiber? > > The stack will look like: > Thread > |- Fiber in D runtime > | |- Call into a C API (stays on same thread) > | | |- Extern (C) callback (stays on same thread) > | | | |- Fiber.yield <-- Is this OK?
I haven't tested this myself, but I *think* it should be OK. One thing to watch out for, though, is the size of the Fiber's stack (this can be specified when you first create the Fiber). If the C part of the code uses up too much stack space (e.g. if somewhere in the C code it tries to allocate a large object on the stack), you may inadvertently overflow the Fiber's stack and cause a crash or abort. Increasing the stack size of the Fiber when it is created should fix this problem. T -- Those who don't understand D are condemned to reinvent it, poorly. -- Daniel N