[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] recursive mutex-lock!
From: |
Tobia Conforto |
Subject: |
Re: [Chicken-users] recursive mutex-lock! |
Date: |
Wed, 27 Feb 2008 01:04:04 +0100 |
(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