Re: volatile or not volatile

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

 



On Fri, Mar 14, 2003 at 12:18:55PM -0800, Seth Arnold wrote:
> On Tue, Mar 04, 2003 at 07:17:49PM +0100, Frank A. Uepping wrote:
> > Do these mechanisms (spinlocks, semaphores, atomic_t) make sure
> > that they always operate on the most actual versions of the shared data?
> > Have I to do some *special action* to ensure this, like qualifying the shared 
> > data volatile?
> > What mechanism exists to enforce *memory sync* anyway?
> 
> Combinbing semaphores or spinlocks with memory barriers will enforce
> this. See mb(), wmb() (write memory barrier), and rmb() (read memory
> barrier).

You don't have to combine them. Spinlocks imply memory barriers.

> Of course, using volatile on primitive types should do the job too.

Unfortunately does not :-(. mb() enforces both optimization and memory
barrier at a given point. volatile enforces optimization barrier on
every access to the variable, but does not enforce memory barrier, so on
SMP machine the other CPU might still get wrong data from cache or
prefetch buffer or something like that.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux