{"id":39133,"date":"2004-05-28T06:59:00","date_gmt":"2004-05-28T06:59:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/05\/28\/high-performance-multithreading-is-very-hard\/"},"modified":"2004-05-28T06:59:00","modified_gmt":"2004-05-28T06:59:00","slug":"high-performance-multithreading-is-very-hard","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040528-00\/?p=39133","title":{"rendered":"High-performance multithreading is very hard"},"content":{"rendered":"<p>Among other things, you need to understand weak memory models.\n  Hereby incorporating by reference  <a href=\"http:\/\/weblogs.asp.net\/brada\/\">Brad Abrams<\/a>&#8216; discussion of  <a href=\"http:\/\/weblogs.asp.net\/brada\/archive\/2004\/05\/12\/130935.aspx\">  volatile and MemoryBarrier()<\/a>.  In particular,  <a href=\"http:\/\/discuss.develop.com\/archives\/wa.exe?A2=ind0203B&amp;L=DOTNET&amp;P=R375\">  Vance Morrison&#8217;s discussion of memory models<\/a>  is important reading.\n  (Though I think Brad is being too pessimistic about volatile.  Ensuring release semantics at the store of &#8220;singleton&#8221;  is all you really need &#8211; you want to make sure the singleton is  fully constructed before you let the world see it.  volatile here is overkill.)\n  Vance&#8217;s message also slyly introduces the concepts of  &#8220;acquire&#8221; and &#8220;release&#8221; memory semantics.  An interlocked operation with &#8220;acquire&#8221; semantics prevents  future reads from being advanced to before the acquisition.  An interlocked operation with &#8220;release&#8221; semantics prevents  previous writes from being delayed until after the release.<\/p>\n<p>  In the absence of explicitly-named memory semantics,  the Win32 Interlocked* functions by default provide  full memory barrier semantics.  However, some functions, like  <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/dllproc\/base\/interlockedincrementacquire.asp\">  InterlockedIncrementAcquire<\/a>,  forego the full memory barrier semantics and provide only  acquire or release semantics.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Among other things, you need to understand weak memory models. Hereby incorporating by reference Brad Abrams&#8216; discussion of volatile and MemoryBarrier(). In particular, Vance Morrison&#8217;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 &#8220;singleton&#8221; is all you really need [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-39133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Among other things, you need to understand weak memory models. Hereby incorporating by reference Brad Abrams&#8216; discussion of volatile and MemoryBarrier(). In particular, Vance Morrison&#8217;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 &#8220;singleton&#8221; is all you really need [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/39133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=39133"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/39133\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=39133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=39133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=39133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}