On 2011-01-30 13:23:16 -0500, Ellery Newcomer
<ellery-newco...@utulsa.edu> said:
Ah, thank you. That clears things up a bit. how do you safely convert
from a shared type to a non shared type or vice versa? a deep copy
inside a critical section?
A copy? Yes. A critical section? Not really.
Shared is about atomic operations, things that the processor can do
atomically without locking. They're used mostly to provide sequential
consistency in our multi-core world where multiple cores can see a
different value for the same memory address at one given time due to
out-of-sync caches. Atomic ops forces the caches to synchronize but are
slower.
You can't mix atomic operations with OS-level locking because they
don't respect each other (a lock won't prevent an atomic read from
occurring). Also, atomic ops are generally limited to word-sized data
structures, sometime double-word. So on a 32-bit processor that's a
32-bit or 64-bit value (assuming the value is properly aligned).
If you want to use locking (a critical section in Windows parlance),
you should put your data in a synchronized class, then share that class
with other threads. If you don't use locking, you have at best
double-word granularity.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/