At 10:26 PM 9/9/00 -0400, Steven W McDougall wrote:
>RFC 178 proposes a shared data model for Perl6 threads. In a shared
>data model
>- globals are shared unless localized
>- file-scoped lexicals are shared unless the thread recompiles the
>   file
>- block scoped lexicals may be shared by
>   - passing a reference to them
>   - closures
>   - declaring one subroutine within the scope of another
>
>In short, lots of stuff is shared, and just about everything can be
>shared.

I snipped out the rest here, since it's just generally wrong. (Subs don't 
need copying, and the optree doesn't currently hold pointers to 
lexicals--if it did recursion wouldn't work)

The current "share everything" model perl 5 uses is too expensive. Far too 
much is shared, and it means that for safety you have to lock and unlock 
everything. Bleah. That costs too much, and you're spending it in the wrong 
places.

The alternate perl 5 model (the one IThreads uses) actually clones off the 
data when a new thread is created. This also can be too darned expensive in 
many cases, since you really only want to access a limited set of data. 
(Though if you're careful about when a thread gets created you can dodge a 
bunch of this)

Both methods have their advantages. And both have their unneeded costs. 
There are even times when they both suck--what happens, for example, if you 
want to fire off a thread in a sub that accesses *no* package variables or 
external lexical state? It's self-contained, but you pay either way.

What would be best is if we instead tried going with Plan B. I'd write this 
up as a formal RFC, but I'm strapped for time, so here's the overview.

Creating a new thread takes two extra sets of flags. They're the same for 
lexical and package variables. These flags can be one of:

*) SHARE_ALL. This marks all the whatevers as shared. Perl flags the data 
elements as shared, and every access to everything costs. No data copying's 
done. Icky, but OK.

*) SHARE_EXPLICIT. When a new thread is created, all the variables marked 
as :shared are shared. All the rest are cloned into the new interpreter

*) SHARE_NOCOPY. When a new thread is created, all the variables marked as 
:shared are shared. All the rest are *gone*. Poof. You get an empty symbol 
table, and no lexical variables are visible. (We may need to provide empty 
variables, since there's no autoviv functionality that'll cover us here) 
Maybe files are shared across threads, but that's it.

When a non-shared variable is put into a shared variable, it becomes 
shared. So if you have this:

   my $foo;
   my @bar : shared;
   push @bar, \$foo;

then $foo becomes shared. Yes, we do walk references and do propagage 
sharedness through containers, so sticking a ref in a shared container 
might get you a pause. Tough noogies, you asked for it. :) (We could warn 
with -w on this)

What the default is would be up in the air. Personally, I like 
share_nocopy, but others might prefer other things.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to