develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH] Adding callbacks to the core

Thread Previous | Thread Next
From:
Dan Sugalski
Date:
August 22, 2001 08:27
Subject:
Re: [PATCH] Adding callbacks to the core
Message ID:
5.1.0.14.0.20010822112016.08c09ab0@tuatha.sidhe.org
At 04:05 PM 8/22/2001 +0100, Dave Mitchell wrote:
>Nicholas Clark <nick@ccl4.org> wrote:
> > [I don't understand threading, but I've read enough from Dan and Alan to
> > learn that multi-CPU boxes will quite happily run different threads of
> > the same process on the different CPUs at the same time, and this often
> > does horrible things to code that was written without thinking about this]
>
>
>IIRC, the main danger is that you cannot assume much about the visibility
>of changes in shared memory between threads: just because thread A on
>CPU 1 wrote to shared memory at location N chronologically before thread
>B on on processor 2 tries to read it, doesnt mean that thread B will see the
>change - due to cache architectures etc.

Yep, though generally once a change is dribbled out to memory, even if it 
stops at a cache, it's globally visible. Where you get bitten is on those 
processors that defer writes to memory and/or write to memory in a 
different order than the code shows.

For example, your code might do:

   foo = 12;
   bar = 15;

but the change to bar might hit memory before the change to foo. (If, for 
example, the processor knows you're going to change or use foo again, or if 
bar's memory location is already in cache so the update's faster, or just 
because the phase of the moon is right)

This can make life very interesting, since you then need to force memory 
write ordering. (Which is both a pain to do cross-platform, and a 
performance loss too, since the processor's executing out-of-order for a 
reason) No fun. Much brain pain involved.

					Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan@sidhe.org                         have teddy bears and even
                                      teddy bears get drunk


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About