In order to change perl6 to support threads, rakudo wants to see more threads examples,
something like rakudos hyper implemented in pir.
my @y = @m »*« @x »+« @b;
Can we get some more specs for exactly what is meant by "hyper implemented in pir".
For example, what function signature should the hyper() opcode have?
We're not looking for a hyper "opcode", unless of course creating new opcodes is Parrot's suggested way to do this.
What I'm looking for are code examples that illustrate Parrot's expectation for implementing threading of a Perl 6 statement like:
my @c = @a »+« @b;
Or, for an even more awesome example, give an example of threading something like:
From a larger perspective: The rakudo & nqp devs are now getting comments like "Parrot has threads now, you just need to modify nqp/rakudo to use them", but we don't have enough details or understanding to be able to do that. Some of the developers also have some doubts about the threading model/implementation itself that need clarification before we can proceed.
So, at this point it would seem most helpful for all of us to have some examples that show how Parrot expects threading to work for some simple Perl 6 constructs, such as the hyperops. Then NQP/Rakudo devs can better understand how to translate Parrot's examples into things that work in our compilation environments, or we can better point out where some of the difficulties lie.
it is a lot of code, but IMO it does @a »+« @b.
@a »+« @b
I remember a talk by nine++ at the YAPC::EU 2012, where he explained the use of green threads, to do something like: "Hey main thread, please set the value of var $x to $y."
So, after some testing I came to this: https://gist.github.com/FROGGS/0cfae647d28c493df73e
add-i-mt.t is working pretty well, but aplusb.nqp only uses fractions of the capacity of other cores when creating the threads, after that, it only uses one core.
Is there a way to work around that? If we can't compute in parallel when lexicals are involved, then I'm not sure how usable it is. I mean, we could clone @a and @b into PMCArrays, write the result into a PMCArray too, but this would only work for native types in combination with the simpliest operations like add.
FROGGS: in fact I still don't know how to do a non blocking lexical lookup
FROGGS: (I am just talking about looking up variables, and subroutine to do some computation, I'm not even talking about writing to a lexical)
rurban: check if the type is a Proxy, follow the proxy then, if not read it directly. if you need to write to a proxy, schedule a writer task
FROGGS: rurban: IIRC the lexical lookup was blocking... you say this is not the case anymore? lexical lookup will happily run in any worker thread?
rurban: FROGGS: every data access is lock-free, just not wait-free
Yes, only the nqp variant of the lexpad pmc is broken, the parrot variant works ok.
src/vm/parrot/pmc/nqplexpad.pmc vs src/pmc/lexpad.pmc