Welcome to the CHICKEN Scheme pasting service

mutexes added by andyjpb on Sun Sep 16 17:50:16 2012

(use srfi-18)

; a mutex.
; 2 threads trying to lock it with and without a timeout


(define m (make-mutex))
(define *timeout* 1)

(define (proc)
  (let ((t (thread-name (current-thread))))
    (printf "~a: Trying\n" t)
    (if (mutex-lock! m *timeout*)
      (begin
	(printf "~a: Locked\n" t)
	(mutex-unlock! m)
	(proc))
      (begin
	(printf "~a: Couldnt'lock\n" t)
	(proc)))))


(thread-start! (make-thread proc))
(thread-start! (make-thread proc))

(let loop () (thread-sleep! 10) (loop))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Name of the bot in #chicken:
Visually impaired? Let me spell it for you (wav file) download WAV