May 28th, 2004

High-performance multithreading is very hard

Among other things, you need to understand weak memory models. Hereby incorporating by reference Brad Abrams‘ discussion of volatile and MemoryBarrier(). In particular, Vance Morrison’s discussion of memory models is important reading. (Though I think Brad is being too pessimistic about volatile. Ensuring release semantics at the store of “singleton” is all you really need – you want to make sure the singleton is fully constructed before you let the world see it. volatile here is overkill.) Vance’s message also slyly introduces the concepts of “acquire” and “release” memory semantics. An interlocked operation with “acquire” semantics prevents future reads from being advanced to before the acquisition. An interlocked operation with “release” semantics prevents previous writes from being delayed until after the release.

In the absence of explicitly-named memory semantics, the Win32 Interlocked* functions by default provide full memory barrier semantics. However, some functions, like InterlockedIncrementAcquire, forego the full memory barrier semantics and provide only acquire or release semantics.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.