<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 22, 2011, at 1:55 PM, Nick Lewycky wrote:</div><blockquote type="cite">On 22 May 2011 13:52, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>></span> wrote:<div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; "><div style="word-wrap:break-word"><div><div class="im"><div>On May 22, 2011, at 1:45 PM, Nick Lewycky wrote:</div></div><div class="im"><blockquote type="cite"><div class="gmail_quote"><div>Back when I thought that we needed to support self-recursive initialization, I came up with a way to do this. The fundamental problem with pthread_self() is that it returns an 8-byte opaque object (ie., they aren't guaranteed to be dense), and C++11's thread library is worse. (Linux supports "gettid()" which returns a 4-byte ID which would fit neatly in the guard variable, but let's leave that aside for the moment.) We can construct our own thread ID by creating a thread_local variable, and we can make it use only 7 bytes by giving it 256 byte alignment. The recursion depth counter would then be kept on the initialization byte (supporting 254 levels of recursion depth with values 0 and 1 reserved for an unlocked guard variable).</div>

</div></blockquote><br></div></div><div>This won't work;  the initialization byte has to stay zero until initialization is complete.</div></div></blockquote><div><br></div><div>My mistake, of course the ABI document states that the first byte must not be modified by __cxa_guard_acquire.</div>

<div><br></div><div>(By the way, unless I missed it, the ABI document never says that the guard variable is initialized to zero. It seems to me that it has to be though...)</div></div></blockquote><br></div><div>I think you can read in a requirement that the first byte be statically initialized to zero, but yeah, I agree that the compiler really must zero-initialize the whole thing.</div><div><br></div><div>John.</div></body></html>