Debug help - ! in data sharing concurrency

Brother Bill brotherbill at mail.com
Sat Aug 30 22:05:49 UTC 2025


A predicate (!*isDone) vs. (*isDone == false) seems to have 
different behavior, where I would expect identical behavior.  
What am I missing?

This program runs forever, even though isDone changes from false 
to true.
```
import std.stdio;
import std.concurrency;
import core.thread;
import core.time : msecs;

void main()
{
	shared(bool) isDone = false;
	spawn(&worker, &isDone);
	writeln("main");

	Thread.sleep(1.seconds);

	// Signalling the worker to terminate:
	isDone = true;
	writeln("main() isDone: ", isDone);
}

void worker(shared(bool)* isDone)
{
	writeln("worker() before while, isDone: ", *isDone);
	while (!*isDone)
	{
		Thread.sleep(250.msecs);
		writeln("worker() isDone: ", *isDone);
	}
}

```

This program properly terminates as expected.
```
import std.stdio;
import std.concurrency;
import core.thread;
import core.time : msecs;

void main()
{
	shared(bool) isDone = false;
	spawn(&worker, &isDone);
	writeln("main");

	Thread.sleep(1.seconds);

	// Signalling the worker to terminate:
	isDone = true;
	writeln("main() isDone: ", isDone);
}

void worker(shared(bool)* isDone)
{
	writeln("worker() before while, isDone: ", *isDone);
	while (*isDone == false)
	{
		Thread.sleep(250.msecs);
		writeln("worker() isDone: ", *isDone);
	}
}

```

Console output:
```
main
worker() before while, isDone: false
worker() isDone: false
worker() isDone: false
worker() isDone: false
main() isDone: true
worker() isDone: true
```


More information about the Digitalmars-d-learn mailing list