[MLton] Int.fmt thread unsafe? (YUCK)
Henry Cejtin
henry.cejtin@sbcglobal.net
Mon, 13 Mar 2006 14:44:46 -0600
By putting the conditional call to more inside the wind you have the
advantage that the critical region is smaller (it does not include more), but
the disadvantage that you have to test b again.
One can eliminate all but one test using the following (rather ugly) code:
fun use (T {more, static, staticIsInUse}, f) =
(Primitive.Thread.atomicBegin ()
; if ! staticIsInUse
then (Primitive.Thread.atomicEnd ()
; f (more ()))
else (staticIsInUse := true
; Primitive.Thread.atomicEnd ()
; DynamicWind.wind (fn () => f static,
fn () => staticIsInUse := false)))
Note, the code for f is now called in two places (with different
continuations) and that might change inlining.