Ok, as the thread function seems pretty basic I have started experimenting
with passing values between threads and sharing variables between threads.
Ideally one would like to do something like
my $foo = "bar";
shared($foo);
iThread->create(sub { $foo = "baz"})->join();
print $foo;
$foo should return baz
Right now I try to allocate a SV outside the perlinterpreter, either by
doing New(0,sv,1,SV); (but that is error prone as I don't understand exactly
what I need to do) or my doing
PERL_SET_CONTEXT(persistant_perl_interperet_never_used) newSV(); and then
return a reference to it, but perl_clone finds it and clones it anyway.
The problem of passing variables between two interpreters is that when the
creating interpreter destructs, it will find all SVs created while it was in
context and kill them. In iThread::Queue I solve this by creating an empy
perl interpreter for every Queue, that seems to be a bit wastefull thou.
One way to solve this is to add in a shared variable flag to a SV and make
perl_clone and perl_destruct leave it alone, I don't know how that will work
with destructing the arenas, (I don't have any clue what the arenas do).
However this requires changes to perl, and while they have been discussed on
p5p I don't want to be reliant on such a change. (However allow for it to be
used once it comes).
I have been thinking of a way to use magic or tie, but I am not entirely
sure how. Anybody with an interesting idea how this could be solved.
Artur