This project is read-only.

Multiple ScriptEngines

Jul 12, 2009 at 4:13 AM


is it possible (or will be possible in the future) to create multiple instances of the ironscheme scriptengine? I tried it with:

_prov = new IronScheme.Hosting.IronSchemeLanguageProvider();
_engine = _prov.GetEngine();

_prov2 = new IronScheme.Hosting.IronSchemeLanguageProvider();
_engine2 = _prov2.GetEngine();

But im always getting an exception. The only way i can think of to create multiple instances so far is to create another appdomain (i didnt tried it yet). But i want mutliple instance within one AppDomain.

Any suggestions?



Jul 12, 2009 at 6:01 AM


I dont think that is possible. I have never tried it.

If you can explain to me in a bit more detail what you are trying to achieve, I could suggest a solution.



Jul 12, 2009 at 1:05 PM

Hi Leppie,

thanks für the fast response. Image an MDI Application, where every Window has its own IronPython Engine. And every Windows has its own worker Thread that is used to load / calculate data.
Those multiple IronPython Engines are used by the multiple Worker Threads, to execute scripts.
Im now trying to replace IronPython with IronScheme. But i dont really know how i should handle the problem to create multiple instance of the IronScheme Engine.



Jul 12, 2009 at 1:26 PM


So you want to run scripts in multiple threads?

I cant quite see why you require separate engines for this, unless you do not want to 'spoil' the top-level of each 'REPL'.



Window 1:

(define a 1)

Window 2:

a => &undefined

(define a 2)

a => 2

Window 1:

a => 1


The above is possible using (new-interaction-environment) for every window and passing that instance to 'eval' as the environment.

For running in separate threads, you can simply create a wrapper around 'eval' and invoke the expression in a thread(s).

I have not tested IronScheme for any concurrency issues, and would appreciate some bug reports if you find them  :)

Hope this helps




Jul 12, 2009 at 2:34 PM

Hi leppie,

ill try it the way you suggest :). Thanks.



Jul 12, 2009 at 3:55 PM
Edited Jul 12, 2009 at 3:56 PM

Hi again

Here is the basic idea:


(import (ironscheme threading))

(define (make-threaded-eval id)
  (let ((env (new-interaction-environment)))
    (lambda (expr)
        (lambda (state)
          (let ((result (eval expr env)))
            (printf "Result on ~a ~s\n" state result)))

(define eval-1 (make-threaded-eval 'thread1))
(define eval-2 (make-threaded-eval 'thread2))

(eval-1 '(define a 1))
(eval-2 '(define a 99))

(eval-1 'a) ;=> 1
(eval-2 'a) ;=> 99

(eval-1 '(set! a -1))
(eval-2 '(set! a -99))

(eval-1 'a) ;=> -1
(eval-2 'a) ;=> -99


You will probably need better thread handling than I used  :)

If you need me to add anything to the threading library, like WaitHandles, just ask.