title: Understanding glibc source code conventions
body: <p>I've been looking at some of the source code for glibc, in particular the nptl code, and I've found it a little bit hard to understand since it seems to have conventions that I'm not familiar with.</p>
  
  <p>For example I was looking at a very small file <a href="http://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_equal.c;h=86279e77b7fda14da9c4c34730703739b4b17d7b;hb=HEAD">pthread_equal.c</a> and there are a few things that I had questions about:</p>
  
  <pre><code>22 int
  23 __pthread_equal (thread1, thread2)
  24      pthread_t thread1;
  25      pthread_t thread2;
  26 {
  27   return thread1 == thread2;
  28 }
  29 strong_alias (__pthread_equal, pthread_equal)
  </code></pre>
  
  <ol>
  <li><p>The declaration on lines 22 and 23 looks like something I understand.  It has a return type of <code>int</code> then the function name <code>__pthread_equal</code> and the parameter list <code>(thread1, thread2)</code>.  But what are the declarations on lines 24 <code>pthread_t thread1;</code> and 25 <code>pthread_t thread2;</code> for?  It looks like these are being declared as global variables but I don't understand the purpose.  I've seen this pattern in many files in the nptl directory and haven't been able to figure out why this is done.</p></li>
  <li><p>What is <code>strong_alias</code>?  A quick Google search has examples of this being used but I did not find a link to any documentation.</p></li>
  <li><p>What is the reason for prefacing some names with two underscores <code>__</code> and some with one underscore <code>_</code>.  Most of the code I've seen uses the two underscores but I think I have seen some places where one underscore is used.  For instance in <a href="http://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthreadP.h;h=68c690e88e9f5c350ac3778e9795f777f633e43b;hb=HEAD#l556">pthreadP.h</a></p>
  
  <pre><code>556 /* Old cleanup interfaces, still used in libc.so.  */
  557 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
  558                                    void (*routine) (void *), void *arg);
  559 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
  560                                   int execute);
  561 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
  562                                          void (*routine) (void *), void *arg);
  563 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
  564                                           int execute);
  </code></pre></li>
  </ol>
  
  <p>Admittedly that code is prefaced with a comment that says "old cleanup interfaces" but either way I'm curious about the difference and why sometimes one underscore is used and sometimes two underscores are used. </p>
  
  <p>Any information regarding these questions is appreciated.</p>