Note that this worked just fine with the old 5.005 threads (which shared everything). I understand that they have ripped the old 5.005 threads out starting with 5.10 but you can still use 5.005 threads with current versions of Perl. We (GreenLight) have been using 5.005 threads in production code for years and it works great (although we did NOT use locks - we count on scheduling).

5.005 threads were a true threading system that was well integrated into Perl and allowed full use of Perl data structures. Eduardo's example shows one of the key advantages: with 5.005 threads you can use any variable normally without restriction. That includes deferencing and updating. All threads work from the same copy. The Perl garbage collector automatically released space when the reference count went to zero. The power of this is somewhat subtle yet easy to use and truly remarkable (I know of no other language that can do this). The ithread copy/share scheme is not nearly as powerful and makes some things virtually impossible (as Eduardo has discovered). Here is a snippet of sample code - if someone can tell me how to do this with ithreads I'll be greatful:

sub newThreadForFoo {
my foo $ref = shift;
Thread->new(sub {wait(3); if ($ref->{Ready} {update($ref)});
}

Don't try this with C/C++ - the value of $ref will be popped off the stack by the time the thread starts. With ithreads $ref cannot be dereferenced and (even if it could) the update routine is given a COPY of $ref and everything that it points to so updating it is useless. Perl with 5.005 threads is the only language I know of that handles this correctly.

I'm not trying to say that ithreads are not a Good and Useful thing - they are just a totally different programming paradigm than 5.005 threads. But ithreads is nowhere near a replacement for 5.005 threads (at least with the current implementation).

At GreenLight are trying to decide what to do in the future - retrofit the old 5.005 code back into 5.10 and beyond or make significant modifications to ithreads so that the 5.005 paradigm can be supported (it isn't clear if the latter is possible).


-------- Original Message --------
Subject: Re: Sharing references which have more than 2 levels of depth
Date: Thu, 20 Feb 2003 13:55:07 +1100
From: Stas Bekman <[EMAIL PROTECTED]>
Organization: Hope, Humanized
To: Eduardo <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
References: <[EMAIL PROTECTED]>



Eduardo wrote:
Hi. I am working in a project of perl in which I use a child thread to continue accepting client connections while the main thread is blocked. My problem is that I need to share a hash which has two levels of depth and I have read in perldoc that ithreads don�t allow to share references which have more than two leves of depth. Is there any posibility to do this or is it impossible?. If it is possible, please, explain me how to declare it. I know declare for one level of depth:

$hash = &share({});

Nothing more. Thank you very much.
I'm not sure whether this will work, but if you do:

my @foo : shared = (1..3);
my @bar : shared;
push @{ $bar[0] }, \@foo;

won't it make bar[0][0] shared as well?


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Reply via email to