Re: Is Accessing a long always thread safe?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sergei (sergei_at_nospam.summertime.mtu-net.ru)
Date: 01/28/05


Date: Fri, 28 Jan 2005 12:23:06 +0300


"Jerry Coffin" <jcoffin@taeus.us> сообщил/сообщила в новостях следующее: news:MPG.1c62b8da9509d9c29897e4@msnews.microsoft.com...
> In article <uCdKK8EBFHA.2112@TK2MSFTNGP14.phx.gbl>,
> sergei@nospam.summertime.mtu-net.ru says...
>
> [ ... ]
>
> > But then it's accesses to cacheable memory that are split across bus width,
> > cache lines, and page boundaries that are not guaranteed to be atomic.
> > Considering that all of this you describe as a bigger problem in SMP
> > systems I come to the conclusion that even on a single CPU system
> > accesses to unaligned memory are not guaranteed to be atomic. And
> > I vaguely recollect that this was not that bad some 10 years ago when
> > I read the 486 manual. Can you point me into the right section of the
> > right manual where this is stated explicitly? I couldn't find it.
>
> The 486 had the same problems, but SMP systems were sufficiently
> unusual at that time that most of the manuals hardly mentioned
> anything about it. As it happens, however, I did some testing at work
> that showed that a dword access on a 486 was not necessarily atomic.
>
> A dword that was dword aligned was accessed atomically, as you'd
> expect.
>
> A dword that was evenly (but not dword) aligned was accessed in two
> word-size pieces.
>
> A dword that was oddly aligned was accessed in three pieces: the
> first byte, then the middle word, then the final byte.

That was always known. This could be a problem if in the middle of
this sequence the same CPU were accessing the memory in some other
thread. And this is what I'm asking about. Can this wierd scenario loom
up with say 'hyperthreading'?

Sergei

> Starting with the Pentium, the external bus changed: they completely
> dropped the three least significant address lines, and added eight
> byte-enable lines instead. The address that's generated is always
> aligned to an 8-byte boundary, and the byte-enable lines determine
> which bytes in that 64-bit word will actually be read. The North
> Bridge then figures out what transactions have to happen on the
> memory bus to retrieve the specified data.
>
> --
> Later,
> Jerry.
>
> The universe is a figment of its own imagination.



Relevant Pages