> DS> I'd definitely rather perl not do any sort of explicit user-level locking. 
> DS> That's not our job, and there be dragons.

> Please explain how this is possible?

Just say no...to locks.


> Does this mean that without user specifying a lock, perl will allow
> a chaotic update pattern to be visible to the user?

I don't know what `chaotic' means. 
The user can certainly create race conditions.

 
>       thread A                        thread B 
>       push(@foo, $bar);               ++$bar;

    #!/my/path/to/perl
    use Thread;

    $bar = 0;
    async { ++$bar }
    push @foo, $bar;
    print $foo[0];


Output: 0 or 1

If the user cares whether the output is 0 or 1, they need to program a
lock. Something like


    #!/my/path/to/perl
    use Thread;

    {
        $bar = 0;
        lock $bar;
        async { lock $bar; ++$bar }
        push @foo, $bar;
    }

    print $foo[0];


Output: 0.


> or
>       $foo{$bar} = $baz;              delete $foo{$bar++};

    #!/my/path/to/perl
    use Thread;

    %foo = ( 1 => 'a', 2 => 'b' );
    $bar = 1;
    $baz = 'x';
    async { delete $foo{$bar++} }
    $foo{$bar} = $baz;
    print $foo{$bar};

Exeuction trace

        Thread1                 Thread2

Case 1

        $foo{$bar} = $baz;
        print $foo{$bar};
                                delete $foo{$bar}
                                $bar++

Output: 'x' 


Case 2

        $foo{$bar} = $baz;
                                delete $foo{$bar}
        print $foo{$bar};
                                $bar++

Output ''


Case 3

        $foo{$bar} = $baz;
                                delete $foo{$bar}
                                $bar++
        print $foo{$bar};

Output 'b'


Case 4

                                delete $foo{$bar}
        $foo{$bar} = $baz;
                                $bar++
        print $foo{$bar};

Output 'b'


Case 5

                                delete $foo{$bar}
                                $bar++
        $foo{$bar} = $baz;
        print $foo{$bar};

Output 'x'


Hey! This is fun :)


> Will there be some sort of coherence here?

What does coherence mean?


- SWM

Reply via email to