(define-macro (my-lock . body) `(let ([result #f]) (if (eq? (mutex-state my-mutex) (current-thread))
Well, the value returned by mutex-state can be either: locked by this thread In this case there can be no race condition, as we own the mutex and nothing is going to take it away from us. locked by another thread abandoned not-abandoned In these cases the mutex is not ours, therefore we don't care if it's locked or not, or if any other thread locks or unlocks it in a race condition, because we'll call mutex-lock! anyway. not-owned This I can't tell, as I have no clue what not-owned means :-)
(set! result (begin ,@body)) ;;else (begin (mutex-lock! my-mutex) (set! result (begin ,@body)) (mutex-unlock! my-mutex))) result))
My ยข2 analysis says you can get away without a conditional lock, if you just ignore the existence of a not-owned state.
Tobia _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users