[M3devel] What's with Atomic*.CompareSwap?

Rodney M. Bates rodney_bates at lcwb.coop
Fri Oct 7 22:05:45 CEST 2016


In trying to remove code generator failures compling calls on Atomic*.CompareSwap,
I find things very confusing.  Parameter 'expected' is declared as VAR, and the
front end is passing it by value, but M3CG_Check wants its type to be as if passed
by value.  All the back ends seem to think it is passed by value also,  But this
would mean it was never updated.

The ubiquitous comment that it is "permitted to fail spuriously" is confusing.
I would have thought "fail" meant return FALSE when it shouldn't, but the sample
loop looks more like "fail" means return FALSE correctly, but not update 'expected'.
Even then, I don't understand the loop.  If it's trying to atomically update
'current' to 'function(current)' wouldn't it be better to keep refetching
'current' every time, instead of 'expected', which, if it differed,, due to
a "spurious failure" (in the latter sense) would be older and less likely to
result in a successful update the next try?

And if 'expected' is never updated, as the back ends appear to be doing,
this loop would have a low probability of ever terminating, since 'desired'
would almost always fail to match 'current'.


-- 
Rodney Bates
rodney.m.bates at acm.org


More information about the M3devel mailing list