On 22 May 2011 13:52, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div style="word-wrap:break-word"><br><div><div class="im"><div>On May 22, 2011, at 1:45 PM, Nick Lewycky wrote:</div><br><blockquote type="cite">On 22 May 2011 12:23, Howard Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span> wrote:<br>

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div></div><div>On May 20, 2011, at 2:11 AM, Nick Lewycky wrote:<br>
<br>
> I've started dipping my toes in the libcxxabi project by implementing a few simple methods. Patch attached, please review!<br>
><br>
> This isn't heavily tested, I'm mostly just trying to make sure I have the style down. Please let me know if we should be using different file names (hard to follow a pattern where there isn't one), of if the private methods in cxa_guard actually belong in an anonymous namespace, etc.<br>





><br>
> Nick<br>
><br>
</div></div>> <libcxxabi-virtual-and-guard.patch><br>
<br>
I disagree with John that your implementation doesn't support the recursive calls for *different* static objects.  I believe it does.</blockquote><div><br></div><div>Thanks. I was just about to write up an email to the same effect. It does support recursive calls for different static objects because the lock it uses is the second byte of the guard variable, not a global (or per-thread) lock.</div>




</div></blockquote><div><br></div></div><div>Yeah, sorry about that.</div><div class="im"><br><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><br></div><div>NIck</div><div><br></div>

</div>