chickadee » srfi-18 » mutex-specific-set!

mutex-specific-set! mutex objprocedure

Stores obj into the mutex's specific field. mutex-specific-set! returns an unspecified value.

    (define m (make-mutex))
    (mutex-specific-set! m "hello")  ==>  ''unspecified''
 
    (mutex-specific m)               ==>  "hello"
 
    (define (mutex-lock-recursively! mutex)
      (if (eq? (mutex-state mutex) (current-thread))
          (let ((n (mutex-specific mutex)))
            (mutex-specific-set! mutex (+ n 1)))
          (begin
            (mutex-lock! mutex)
            (mutex-specific-set! mutex 0))))
 
    (define (mutex-unlock-recursively! mutex)
      (let ((n (mutex-specific mutex)))
        (if (= n 0)
            (mutex-unlock! mutex)
            (mutex-specific-set! mutex (- n 1)))))