notjack
2020-1-18 08:20:20

Is box-cas! guaranteed to terminate, no matter what any other threads are doing to the box?


lexi.lambda
2020-1-18 11:17:41

box-cas! is a constant-time operation, since it doesn’t spin. There are not any fairness guarantees about repeated calls to box-cas!.


notjack
2020-1-18 11:20:52

I believe you when its compiled to a hardware compare-and-set, but the docs don’t say anything about the software implementation when racket is compiled without support for futures.


notjack
2020-1-18 11:21:28

And the “If no other threads or futures attempt to access box, the operation is equivalent to…” wording in the docs has me suspicious


lexi.lambda
2020-1-18 11:55:17

@notjack When Racket is not compiled with support for futures, the runtime just implements box-cas! as a totally standard read, compare, set sequence in atomic mode, since there’s no parallelism anyway.


lexi.lambda
2020-1-18 12:00:46

The “if no other threads or futures” sentence is just intended to provide an informal illustration of what the operation does. Without futures, you could make the code example accurate without the caveat by doing it in atomic mode. With futures, atomic mode isn’t enough, either. But it’s still constant time either way.


notjack
2020-1-18 12:06:59

okay good, thanks for the sanity check