Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

sky (1411)

  (email not shown publicly)

sky on IRC

Journal of sky (1411)

Thursday April 26, 2001
12:37 AM

Found a way to clone CV

[ #102 ]

One of the problems in the inital version of iThread was the arguments passed to the new thread.

This is basicly what happens

void create(SV* start_function, SV* start_param) {
    new_interp = clone(main_interp)

However this was horribly broken because that start_function was passed in from the main interpretor and was a CV reference INTO that interpretor, so the cloned interpretor was executing the main interpretors CV, this caused race condtions when multiple threads were executing the same CV.

The same problem applied to parameters, they were also refernced by the original interpreter, this caused confusion with regard to refcounts and destruction, and could cause races in some cases.

The solution to this problem was either to use dclone and the perl function cv_clone, however I couldn't get this to properly work, or to use the functionality of perl_clone.

This solution might be called a bit hackery, but hey I am a hacker :).

We take the parameters, we stash them away in $iThread::tempstorage, we clone, we fetch them back from $iThread::tempstorage in the clone, we undef them in both cases! Voila we now have a complete clone of the parameter data.

Next upcoming problem is, returning data from the thread to join, and somehow supporting iThread->join_all()