Found a way to clone CV

sky on 2001-04-26T05:37:12

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) call_sv(start_function) }

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()