If anyone would like to help review a little thread synchronization, I have an example.
The motivation:
-
A worker thread updates (
set!
s) a couple increasing integer variables. -
Some other threads need to wait until those variables are
>=
certain values. -
Instead of the waiters inefficiently busy-looping, I wanted to arrange it so that the worker thread making progress could wake up each waiter when its desired condition is reached.
-
Note: The values always increase, so if a condition becomes true, it remains true. Which I think simplifies this a little.
The least-worst thing I was able to come up with so far:
This performs well (enough for my benchmarks) and has no bugs (that I've discovered yet).
But I can't help wondering if I'm:
-
Overlooking some other, better way to do this in Racket?
-
Re-inventing some wheel? (This feels vaguely like so-called "condition variables" but I have zero hands-on mileage with that; from what I've read so far that feels more general than what I need here.)