chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] critical-section not in Chicken 3?


From: Elf
Subject: Re: [Chicken-users] critical-section not in Chicken 3?
Date: Tue, 5 Feb 2008 09:30:20 -0800 (PST)


im pretty sure you need mutexes.  its pretty easy though...

(define-macro (protect-section ml . body)
    `(if (list? ,ml)
         (let ((retval)   (begin
                              (for-each (lambda (x) (mutex-lock! x #f #f) ,ml)
                              ,@body)))
             (for-each mutex-unlock! ,ml)
             retval)
         (let ((retval    (begin
                              (mutex-lock! ,ml #f #f)
                              ,@body)))
             (mutex-unlock! ,ml)
             retval)))

this should work for any number of mutexes passed into protect-section.
if you want an only-single-mutex case, define the mutex (lets call it mtx)
and then :
(define-macro (protect-section . body)
    `(let ((retval   (begin
                         (mutex-lock! mtx #f #f)
                         ,@body)))
        (mutex-unlock! mtx)
        retval))

should work.

-elf


On Tue, 5 Feb 2008, Graham Fawcett wrote:

Hi folks,

I'm porting some old code that had a (critical-section) in it, to ensure
that a set of instructions was completed atomically with respect to the rest
of the program. But it looks like critical-section is no longer supported in
Chicken 3.

I could move to mutexes, but it will be a bit of a pain. Is there any way to
emulate (critical-section) in Chicken 3, or has the runtime changed so that
it's no longer possible?

Thanks,
Graham





reply via email to

[Prev in Thread] Current Thread [Next in Thread]