This little piece of code runs the subroutine "_foo" in a separate
thread inside interpreter P5.
There are of course a lot of things missing, ParrotInterpreter::clone
does only very basic things and so on, but it runs.
Some remarks and thoughts:
1) We have to store the Parrot_thread somewhere - I'm thinking of:
struct thread_data inside the interpreter structure
2) All interpreters get stored in a global Interp_Array, the index being
the user visible thread id for e.g. join.
3) Shared PMCs should probably get their own pmc-pool memory.
4) above code snippet could be one single op:
thread (out INT, in PMC) # run sub $2 threaded, ret thread id in $1
Further pointers and comments are very welcome.
Have fun,
leo
I think I'd like to start new threads a bit differently, at least
much more explicitly than an invoke. Invoke on an interpreter
arguably ought to dispatch to the interpreter *without* starting a
new thread.
We also need to work out the details of what and how we clone and
create new interpreters, what gets copied and what doesn't. I see
that thread's already started, though. :)
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk
> I think I'd like to start new threads a bit differently, at least
> much more explicitly than an invoke. Invoke on an interpreter
> arguably ought to dispatch to the interpreter *without* starting a
> new thread.
Its not invoking the interpreter, the "thread" method of a ParrotThread
is invoked. Actually the example is a bit outdated - the clone is gone
and a new .ParrotThread is instantiated. it should read now or finally:
new P2, .ParrotThread
set S0, "thread" # or better "start" or "run"
find_global P5, "_foo"
set P6, arg1
callmethcc
It should be the same calling sequence as doing a method call on a new
ParrotThread or any other object. But P2/P5 object passing did interfer.
> We also need to work out the details of what and how we clone and
> create new interpreters, what gets copied and what doesn't. I see
> that thread's already started, though. :)
Yep. Currently its the register file to get things running, nothing
more.
"Subject: threads and shared interpreter data structures"
has an example of one of the problems I encountered til now.
leo