chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] eval and srfi-18 threads


From: Andy Bennett
Subject: [Chicken-users] eval and srfi-18 threads
Date: Thu, 08 Nov 2012 01:13:03 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.9) Gecko/20121014 Icedove/10.0.9

Hi,

I have found a race condition: please can anyone help me isolate it?

I'm using 4.7.0.

Currently I have a requirement for environments in my widget rendering
code so I can't move to 4.8.0.

I have produced the repro case below. I originally saw the behaviour in
my app which uses spiffy, srfi-18 threads, environments and a host of
other eggs. This often causes spiffy requests to throw exceptions,
especially when there are lots of concurrent page-loads in progress.



-----
(use environments miscmacros srfi-18)

(define widget-eval-env (make-parameter (environment-copy
(scheme-report-environment 5) #t)))

(define (render-widgets sxml env default-bindings bindings contents)
  (let ((add-attr (lambda (attr) (environment-set! env (first attr)
(second attr)))))
    (if (list? default-bindings) (for-each add-attr default-bindings))
    (if (list? bindings) (for-each add-attr bindings))
    (environment-set! env 'contents contents)
    (eval `(let ((++ string-append)) ,sxml) env))) ; Render the widget

(define (render sxml default-bindings bindings contents)
 (let* ((env (environment-copy (widget-eval-env) #t))
        (sxml (render-widgets sxml env default-bindings bindings contents)))
  sxml))


(dotimes (t 10)
  (thread-start!
    (make-thread
      (lambda ()
        (printf "Hello ~A\n" t)
        (dotimes (c 1000)
          (render '`(test ,a ,b ,c)
                  '((c "Cee"))
                  `((a "Aay") (b "Bee") (c ,c))
                  '()))
        (printf "Goodbye ~A\n" t)))))
-----

Running this in csi thusly:

-----
$ csi
...
#;1> (load "exn-repro.scm")
-----

Often results in an error such as the following:

-----
Warning (#<thread: thread88>): unbound variable: c

        Call history:

        <eval>    (##sys#list (##core#quote test) a b c)        <--
-----


Subsequent calls to '(load "exn-repro.scm")' in the same csi session do
not seem to produce the exception.

I have seen the unbound variable being many different things, including
"render" which is defined as a procedure in the top level.


I have been unable to reproduce this behaviour with a srfi-18 only case:

-----
(use miscmacros srfi-18)

(define (render sxml default-bindings bindings contents)
  (cons (cons (cons bindings contents) default-bindings) sxml))

(dotimes (t 10)
  (thread-start!
    (make-thread
      (lambda ()
        (printf "Hello ~A\n" t)
        (dotimes (c 100000)
          (render '`(test ,a ,b ,c)
                  '((c "Cee"))
                  `((a "Aay") (b "Bee") (c ,c))
                  '()))
        (printf "Goodbye ~A\n" t)))))
-----

I wonder if it's something to do with environments?


Does anyone have any tips for isolating this further?






Regards,
@ndy

-- 
address@hidden
http://www.ashurst.eu.org/
0x7EBA75FF




reply via email to

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