<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks for the answer.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 12, 2015, at 9:42 AM, David Majnemer <<a href="mailto:david.majnemer@gmail.com" class="">david.majnemer@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Fri, Jun 12, 2015 at 7:56 AM, Mehdi Amini<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Hi Reid,<br class=""><br class="">Can you explain how the change makes it thread safe? It’s not obvious to me right now.<br class=""></blockquote><div class=""><br class=""></div><div class="">In the MSVC world, loads marked volatile have acquire semantics and stores marked volatile have release semantics.  We actually don't need such strong semantics here, just a monotonic guarantee on the loads and stores which volatile will more or less give us on GCC (for mingw builds and the like).</div><div class=""><br class=""></div><div class="">It contains a benign race but we are OK with that (two threads might both compute the allocation granularity but they will both produce the same result.)</div></div></div></blockquote><div><br class=""></div><div>I see, we’re fine with a race on the initialization in the sense that it can happen multiple times (since I guess getAllocationGranularity() is pure) but it has to be visible in each thread. </div><div><br class=""></div><div>Also I read online that MSVC 2013 should support thread-safe local static initialization (see: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__herbsutter.com_2013_09_09_visual-2Dstudio-2D2013-2Drc-2Dis-2Dnow-2Davailable_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=ajJzj9__XPDfED0Hvp5BqX1g_0KPQrMIbRCF9RhYxBI&s=v3smw17mFexW3ydVLTlE8073NmqbOY0gbseAi0p_qtU&e=" class="">http://herbsutter.com/2013/09/09/visual-studio-2013-rc-is-now-available/</a> )</div><div>Isn’t MSVC2013 the current minimal version for LLVM?</div><div><br class=""></div><div>Thanks,</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><br class="">Thanks,<br class=""><br class="">Mehdi<br class=""><div class="HOEnZb"><div class="h5"><br class="">> On Jun 11, 2015, at 3:22 PM, Reid Kleckner <<a href="mailto:reid@kleckner.net" class="">reid@kleckner.net</a>> wrote:<br class="">><br class="">> Author: rnk<br class="">> Date: Thu Jun 11 17:22:45 2015<br class="">> New Revision: 239566<br class="">><br class="">> URL:<span class="Apple-converted-space"> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239566-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=ajJzj9__XPDfED0Hvp5BqX1g_0KPQrMIbRCF9RhYxBI&s=QmgljVWBK5mGjbOjmyu88Y84_63O8WA4pXK1to5iWDk&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=239566&view=rev</a><br class="">> Log:<br class="">> [Support] Fix a race initializing a static local in MSVC<br class="">><br class="">> static local initialization isn't thread safe with MSVC and a race was<br class="">> reported in PR23817. We can't use std::atomic because it's not trivially<br class="">> constructible, so instead do some lame volatile global integer<br class="">> manipulation.<br class="">><br class="">> Modified:<br class="">>    llvm/trunk/lib/Support/Windows/Memory.inc<br class="">><br class="">> Modified: llvm/trunk/lib/Support/Windows/Memory.inc<br class="">> URL:<span class="Apple-converted-space"> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Support_Windows_Memory.inc-3Frev-3D239566-26r1-3D239565-26r2-3D239566-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=ajJzj9__XPDfED0Hvp5BqX1g_0KPQrMIbRCF9RhYxBI&s=rfWWNaEBRVk4aIOOOsJIhg1X3T3PNkeNoX6f6YbS4gI&e=" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Memory.inc?rev=239566&r1=239565&r2=239566&view=diff</a><br class="">> ==============================================================================<br class="">> --- llvm/trunk/lib/Support/Windows/Memory.inc (original)<br class="">> +++ llvm/trunk/lib/Support/Windows/Memory.inc Thu Jun 11 17:22:45 2015<br class="">> @@ -78,7 +78,15 @@ MemoryBlock Memory::allocateMappedMemory<br class="">>   // While we'd be happy to allocate single pages, the Windows allocation<br class="">>   // granularity may be larger than a single page (in practice, it is 64K)<br class="">>   // so mapping less than that will create an unreachable fragment of memory.<br class="">> -  static const size_t Granularity = getAllocationGranularity();<br class="">> +  // Avoid using one-time initialization of static locals here, since they<br class="">> +  // aren't thread safe with MSVC.<br class="">> +  static volatile size_t GranularityCached;<br class="">> +  size_t Granularity = GranularityCached;<br class="">> +  if (Granularity == 0) {<br class="">> +    Granularity = getAllocationGranularity();<br class="">> +    GranularityCached = Granularity;<br class="">> +  }<br class="">> +<br class="">>   const size_t NumBlocks = (NumBytes+Granularity-1)/Granularity;<br class="">><br class="">>   uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) +<br class="">><br class="">><br class="">> _______________________________________________<br class="">> llvm-commits mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">><span class="Apple-converted-space"> </span><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></div></blockquote></div></div></blockquote></div><br class=""></div></body></html>