[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gwydion & threads



Eric Gouriou wrote:
>  Moreover you do not want to use atomic writes for each
> descriptor_t access, as atomic writes typically have
> memory barriers semantics that will kill the memory system
> performance.

This is the key point.  You *really* don't want a memory model where
ordinary memory accesses are safe across threads if you want decent
perforamnce on a multiprocessor system.  Even if you know that memory
writes are "atomic", how do you know that the compiler is writing a
value to memory at all, when it could just store the value in a register
for writing "later?"

Take a look at the memory-model semantics for pthreads and Java, both of
which basically say that you can't assume *anything* about memory
written in one thread and read from another thread until you have
crossed a synchronization boundary.  In Java this means that the writer
has exited a synchronization block and then the reader has entered one. 
In pthreads it means that the the writer has locked or unlocked a mutex
and then the reader has locked or unlocked a mutex.