> > You aren't being clear here.
> > 
> >         fetch($a)               fetch($a)
> >         fetch($b)               ...
> >         add                     ...
> >         store($a)               store($a)
> > 
> > Now all of the perl internals are done 'safely' but the result is garbage.
> > You don't even know the result of the addition.
> 
> Sorry you are right, I wasn't clear.  You are correct - the final value
> of $a will depend on the exact ordering of the FETCHEs and STOREs in the
> two threads.  

mmmm...I hadn't been thinking in terms of the stack machine. OK, we
could put the internal locks around fetch and store. Now, can everyone
deal with these examples

Example

    $a = 0;
    $thread = new Thread sub { $a++ };
    $a++;
    $thread->join;
    print $a;

Output: 1 or 2


Example

    @a = ();
    async { push @a, (1, 2, 3) };
    push @a, (4, 5, 6);
    print @a;

Possible output: 142536


- SWM

Reply via email to