On Tue, Mar 04, 2008 at 04:37:29PM +0000, Andrew Haley wrote: > >Typically those would be found in asm statements. > > >I suspect it would be valuable to have standardized primitives for > >atomic actions (semaphores, spinlocks, test-and-set primitives, > >circular buffers, pick one). > > We already have these in gcc, and they're even documented.
We don't have atomic read or atomic write builtins (ok, you could abuse __sync_fetch_and_add (&x, 0) for atomic read and a loop with __sync_compare_and_swap_val for atomic store, but that's a horrible overkill. Being able to assume that for non-bitfield accesses bigger than certain minimum size, smaller or equal to the word size and naturally aligned the compiler will read or write a value in one lump is certainly desirable and many programs assume it heavily (starting with glibc, kernel, libgomp, ...). The "certain minimum size" is typically either size of char, or (e.g. on old alphas) size of int. Typically the programs care about atomicity of accesses to int, long and pointer sized vars, e.g. have only threads in a critical section modify a variable, but be able to read that variable outside of critical section and see only values that were written in the critical section, not say half of an old value and half of a new value. Jakub