Re: compiler / hardware reordering

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

 



Mark Farnell wrote:
In the following code:

a++

if (a > 5) {
  .....
} else {


}

Is it possible for "a++" to be swapped with the if-block?  If so, then
can I stop this reordering by making a as atomic_t?
I don't think it would happen, but I could be wrong.


In the second case:
....
spin_lock(&lock);
a++;
spin_unlock(&lock);
....
Is it possible for instructions to be reordered across a spin_lock
primitive?  If this is possible, then spinlocks will be pretty
useless........
Two types of reordering.
Compiler reordering instructions : can be fixed by intrducing a barrier() call
CPU re ordering instructions: use a mb()/rmb()/wmb()
Spin locks would do the trick as well.

Thanks,
Om.


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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