how to cast away 'volatile'?
Kevin P. Fleming
kpfleming@starnetworks.us
Tue Mar 13 16:02:00 GMT 2007
Ian Lance Taylor wrote:
> That means that the only correct way to share a memory buffer between
> threads is to use a mutex, and it means that the mutex code can not be
> written in standard conformant C. The mutex code must use asm
> statements to insert memory barriers as required (on the x86 a lock
> prefix serves as a memory barrier (except that some specific x86
> processors have bugs, but I digress...)).
This comment makes me curious, since I see (and work on) plenty of code
that shares data structures between threads using only a mutex for
protection and no memory barrier instructions of any kind. This code is
using standard POSIX threading constructs and seems to work fine on
multi-CPU and multi-core systems, both x86 and other flavors.
Are you referring to a specific sort of memory sharing between threads
here, or are you saying that you think that _all_ objects shared between
threads need to be protected in this way?
More information about the Gcc-help
mailing list