Re: Are Perl6 threads preemptive or cooperative?

2000-08-25 Thread Markus Peter

--On 25.08.2000 20:02 Uhr -0400 Steven W McDougall wrote:

 Others have pointed out that code inside sub-expressions and blocks
 could also assign to our variables. This is true, but it isn't our
 problem. As long as each assignment is carried out correctly by the
 interpreter, then each variable always has a valid value, computed
 from other valid values.

Depends on who 'our' is, if you're an internals guy you need not care, 
that's true, but as a user of the language you care about how much sync-ing 
you have to do yourself in your perl code - the preemptive vs. cooperative 
discussion is there valid as well though it would probably be good to 
seperate these discussions :-)

-- 
Markus Peter - SPiN GmbH
[EMAIL PROTECTED]




Threads and file-scoped lexicals

2000-08-25 Thread Steven W McDougall

Do separate threads 
- all see the same file-scoped lexicals
- each get their own file-scoped lexicals


#!/usr/local/bin/perl

use Threads;

my $a = 0;

my $t1 = Thread-new(\inc_a);
my $t2 = Thread-new(\inc_a);

$t1-join;
$t2-join;

print "$a";

sub inc_a
{
$a++;
}

What should the output be? 0? 1? 2?


- SWM



Threads and run time/compile time

2000-08-25 Thread Steven W McDougall

RFC1v3 says

5. Threads are a runtime construct only. Lexical scoping and
compile issues are independent of any thread boundaries. The
initial interpretation is done by a single thread. use Threads may
set up the thread constructs, but threads will not be spawned
until runtime.

However, the distinction between compile time and run time that it
relies on doesn't exist in Perl. For example, if we chase through
perlfunc.pod a bit, we find

use Module;

is exactly equivalent to

BEGIN { require Module; import Module; }
and
require Module;

locates Module.pm and does a

do Module.pm

which is equivalent to

scalar eval `cat Module.pm`;

and eval is documented as

 eval EXPR
   
 the return value of EXPR is parsed and
 executed as if it were a little Perl program.


Users can (and do) write open code in modules.
There is nothing to prevent users from writing modules like

# Module.pm
use Threads;

Thread-new(\foo);

sub foo { ... }


Users can also write their own BEGIN blocks to start threads before
the rest of the program has been compiled

sub foo { ... }

BEGIN { Thread-new(\foo) }


Going in the other direction, users can write

require Foo.pm

or even

eval "sub foo { ... }";

to compile code after the program (and other threads) have begun execution.


Given all this, I don't think we can sequester thread creation into
"run time". We need a model that works uniformly, no matter when
threads are created and run.


- SWM