Anonymous user
Mutex: Difference between revisions
→{{header|Racket}}
Line 645:
Racket has semaphores which can be used as mutexes in the usual way. With other language features this can be used to implement new features -- for example, here is how we would implement a protected-by-a-mutex function:
<lang
(define foo
(let ([sema (make-semaphore 1)])
(lambda (x)
Line 652 ⟶ 653:
(λ() (semaphore-post sema))))))</lang>
and it is now easy to turn this into a macro for definitions of such functions:
<lang racket>
(define name
(let ([sema (make-semaphore 1)])
(lambda (arg ...)
(dynamic-wind (
(
(
;; this does the same as the above now:
(define/atomic (foo x)
|