Hi Slava, Hello everyone,

Here's my attempt at making Factor reentrant, which actually turned out 
to be a lot easier than I thought. (that's more a testament to how clean 
Slava's vm code is than skill on my part)

http://github.com/phildawes/factor/tree/reentrantvm

Caveat: I've only tried this on ubuntu 9.04 64bit as I don't have a 
windows or mac box, sorry. I'd appreciate it if people with those 
platforms could give it a go.

I made the following modifications to the vm:

- Modified all global variables so that they're thread local
- In code_heap.cpp I moved initialisation of the code heap forwarding 
map to the init fn (rather than load time)
- In os-unix.cpp I hacked the nonblockingio stdin_loop thread to work in 
an MT environment
- In factor.cpp I added a 'start_standalone_factor_in_new_thread' 
function to spawn a new vm

I think that's it. I haven't tested this heavily so there may be stuff 
I've missed, but it looks like it works ok. If you want to try it I've 
put a scratch vocab called 'osthreadhack' in resource:work:

---- osthreadhack.factor ----

USING: alien.syntax io.encodings.utf8 kernel sequences unix.utilities ;
IN: osthreadhack

FUNCTION: void start_standalone_factor_in_new_thread ( int argc, char** 
argv ) ;

: start-vm-in-os-thread ( argv -- )
     [ length ] [ utf8 strings>alien ] bi 
start_standalone_factor_in_new_thread ;

: start-tetris-in-os-thread ( -- )
     { "./factor" "-run=tetris" } start-vm-in-os-thread ;

----

So to test you can fire up the factor gui or listener and type:

        USE: osthreadhack
        4 [ start-tetris-in-os-thread ] times

and four tetris windows pop up. Sweet. For an added bonus if you don't 
have tetris in your your image you can witness all your cpu cores 
melting as 4 factor vms compile stuff in parallel.

Obviously this is just a bit of a hack at the moment so I don't expect 
this to go into trunk, but I'd be interested in knowing if you're open 
to the idea of getting some OS-thread features in factor before 1.0?

Cheers,

Phil


------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to