www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using Fibers without yield

reply Unthread <call 3142.casa> writes:
Is there any reason for this behavior?
```D
import std.stdio, core.thread.fiber;

Fiber one, two;

void main() {
	one = new Fiber(
		delegate() {
			while(1) {
				stderr.writefln("one says two.state = %s", two.state);
				two.call();
			}
		}
	);
	two = new Fiber(
		delegate() {
			while(1) {
				stderr.writefln("two says one.state = %s", one.state);
				one.call();
			}
		}
	);
	one.call();
}
```
Execution of one is suspended when it calls two, but then two 
reports the state of one is not HOLD.
```
one says two.state = HOLD
two says one.state = EXEC
one says two.state = EXEC
Segmentation fault
```
Is this a bug or a feature? If the last then why?
Nov 27 2025
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Here is the source code: 
https://github.com/dlang/dmd/blob/master/druntime/src/core/thread/fiber/base.d

When you call the second fiber, the first is still executing as far as 
the call stack is concerned. It was never yielded.

D's Fiber is a primitive, it has no scheduler or dependency management.

It cannot do anything differently.
Nov 27 2025
parent Serg Gini <kornburn yandex.ru> writes:
On Friday, 28 November 2025 at 07:14:42 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 Here is the source code: 
 https://github.com/dlang/dmd/blob/master/druntime/src/core/thread/fiber/base.d

 When you call the second fiber, the first is still executing as 
 far as the call stack is concerned. It was never yielded.

 D's Fiber is a primitive, it has no scheduler or dependency 
 management.

 It cannot do anything differently.
I find it is quite unintuitive saying "has no scheduler" when in std we have this https://dlang.org/library/std/concurrency/fiber_scheduler.html
Nov 28 2025