atomic operations

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Sun Feb 24 18:24:21 EST 2013


On Sun, 24 Feb 2013 11:50:14 +0100, richard -rw- weinberger said:
> On Sun, Feb 24, 2013 at 10:42 AM, Shraddha Kamat <sh2008ka at gmail.com> wrote:
> > what is the relation between atomic operations and memory alignment ?
> >
> > I read from UTLK that "an unaligned memory access is not atomic"
> >
> > please explain me , I am not able to get the relationship between
> > memory alignment and atomicity of the operation.
>
> Not all CPUs support unaligned memory access, such an access may cause a fault
> which needs to be fixed by the kernel...

There's a more subtle issue - an unaligned access can be split across a cache
line boundary, requiring 2 separate memory accesses to do the read or write.
This can result in CPU A fetching the first half of the variable, CPU B
updating both halves, and then A fetching the second half of the now updated
variable.. This can bite you even on CPUs that support unaligned accesses.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130224/d2bc34b0/attachment.bin 


More information about the Kernelnewbies mailing list