> SWM> Question: Can the interpreter determine when a variable becomes
> SWM> shared?

> SWM> Answer: No. Then neglecting to put a :shared attribute on a shared
> SWM> variable will crash the interpreter. This doesn't seem very Perlish.

> Err, no. It won't crash the interpreter. It'll make the script operate
> incorrectly.

This is just the distinction that I am concerned about.

In RFC 178, I used the term *data coherence* to mean that the
interpreter won't crash or corrupt its internal data representation,
and the term *data synchronization* to mean that the program actually
does what the user wants. Perhaps we could use the terms *internal*
thread-safety and *external* thread-safety, instead.

Here is an example of what can happen without internal thread-safety

Perl source:

    Thread1                         Thread2 
    $a = 'a';                       $a = 'a' x 1_000_000;

Exeuction trace (C language pseudo code)

    a.size = 1;
    a.data = malloc(a.size);
                                    a.size = 1000000;
    memset(a.data, 'a', a.size);

Crash.
Crash & Burn.
Do not pass Go, 
Do not collect $200.


Here is an example of what can happen without external thread-safety

Perl source:

    Thread1                         Thread2
    $a = 'a';                       $a = 'a' x 1_000_000;
    print "Thread1 $a";


Execution trace (Perl code)

    $a = 'a';                       
                                    $a = 'a' x 1_000_000;
    print $a;

and the user gets 999,999 more characters of output than they expect.


If the users cares about external thread-safety, they have to do their
own synchronization

Perl source:

    Thread1                         Thread2
    lock $a;
    $a = 'a';                       $a = 'a' x 1_000_000;
    print "Thread1 $a";

Now the output is guaranteed to be `a'.


All I want the language to guarantee is internal thread-safety.
Everything else is the user's problem.


- SWM

Reply via email to