title: Why is _GNU_SOURCE macro required for pthread_mutexattr_settype() while it is in POSIX/IEEE standard?
body: <p>I have written a <strong>multithread server program</strong> in C, which echoes back all the data that a client sends.  </p>
  
  <p>Initially, I used <code>poll()</code> function in my program to detect <code>POLLRDHUP</code> event, for that I defined <code>_GNU_SOURCE</code> macro (This event is defined <a href="http://manpages.courier-mta.org/htmlman2/poll.2.html" rel="noreferrer">here</a>). </p>
  
  <p>Later I updated my code &amp; removed <code>poll()</code> function, however I forgot to remove <code>_GNU_SOURCE</code> macro.  </p>
  
  <p>Now my code is finally complete (and a little long to post, more than 250 lines). Before removing macro I was compiling my program using:</p>
  
  <pre class="lang-c prettyprint-override"><code>gcc multi_thread_socket_v4.c -Wall -Werror -g -lpthread -o multi_thread_socket
  </code></pre>
  
  <p>and it worked fine: No errors, no warnings</p>
  
  <p><strong>After I removed the macro definition</strong>, and compiled using same command-line, the output of gcc was:</p>
  
  <pre><code>multi_thread_socket_v4.c: In function ‘main’:
  multi_thread_socket_v4.c:194: warning: implicit declaration of function ‘pthread_mutexattr_settype’
  multi_thread_socket_v4.c:194: error: ‘PTHREAD_MUTEX_ERRORCHECK’ undeclared (first use in this function)
  multi_thread_socket_v4.c:194: error: (Each undeclared identifier is reported only once
  multi_thread_socket_v4.c:194: error: for each function it appears in.)
  </code></pre>
  
  <p>I have <strong>included all the required libraries</strong> as it worked fine initially.</p>
  
  <p>I peeked into <code>pthread.h</code> at <code>/usr/include/pthread.h</code> and found out this:</p>
  
  <pre class="lang-c prettyprint-override"><code>/* Mutex types.  */
  enum
  {
    PTHREAD_MUTEX_TIMED_NP,
    PTHREAD_MUTEX_RECURSIVE_NP,
    PTHREAD_MUTEX_ERRORCHECK_NP,
    PTHREAD_MUTEX_ADAPTIVE_NP
  #ifdef __USE_UNIX98
    ,
    PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
    PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
    PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
    PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
  #endif
  #ifdef __USE_GNU
    /* For compatibility.  */
    , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
  #endif
  };
  </code></pre>
  
  <p>and this:</p>
  
  <pre class="lang-c prettyprint-override"><code>#ifdef __USE_UNIX98
  /* Return in *KIND the mutex kind attribute in *ATTR.  */
  extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
                        __attr, int *__restrict __kind)
       __THROW __nonnull ((1, 2));
  
  /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
     PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
     PTHREAD_MUTEX_DEFAULT).  */
  extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
       __THROW __nonnull ((1));
  </code></pre>
  
  <p>I <a href="http://linux.die.net/man/7/feature_test_macros" rel="noreferrer">checked out here</a> to check if <code>__USE_UNIX98</code> is a feature test macro, but it was not there.</p>
  
  <p>So please <strong>help me understanding the reasons for the error,</strong> because <strong>the function &amp; the macro where <code>gcc</code> shows error <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html" rel="noreferrer">are defined in POSIX standard</strong></a>. I do not know what more info regarding my problem will be required so please tell me, I will update my question.</p>