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



_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to