title: Semaphore, sem_post and segmentation fault
body: <p>I have a problem with segmentation fault when I call <code>sem_post()</code> function. Here is my code (it's checking timeout):</p>
  
  <p>Parent thread:</p>
  
  <pre><code>void * Client::Init(void * args)
  {
      char * clientIP;
      // clientIP = ... IP from other program part
  
      int * timeoutSemaphoreValue;
  
      sem_unlink(clientIP); // always new semaphore
  
      sem_t * semaphore;
      semaphore = sem_open(clientIP, O_CREAT | O_EXCL, O_RDWR, 0);
  
      if(errno == EEXIST)
           cout &lt;&lt; "Problem z synchronizacją wątków (semafory) - nieobsłużone." &lt;&lt; endl;
  
      pthread_create(&amp;clientStatesThread, NULL, VOID_T Client::ClientStatesLoop, clientIP);
  
      while(status &gt; 0)
      {   
           sem_getvalue(semaphore, timeoutSemaphoreValue);
  
           if(*(client-&gt;timeoutSemaphoreValue) == 1)
                 throw SocketException(0x01, "Timeout.", errno)
      }
  }
  </code></pre>
  
  <p>And a child thread method:</p>
  
  <pre><code> void * Client::ClientStatesLoop(void * args)
   {
       char * clientIP = (char *)args;
  
       sem_t * semaphore;
       semaphore = sem_open(clientIP, O_CREAT, O_RDWR, 0);
  
       setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&amp;tv, sizeof (struct timeval));
  
       ...
  
       while(1)
       {
            bufferInLen = recv(fd, bufferIn, BUF_SIZE, 0);  
            if((errno == EAGAIN) || (errno == EWOULDBLOCK))
            {
                sem_post(semaphore);
            }
       }
   }
  </code></pre>
  
  <p>Here is GDB log:</p>
  
  <pre><code>[Thread debugging using libthread_db enabled]
  Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
  TCP Server v.2.0
  [New Thread 0x7ffff6fd6700 (LWP 2425)]  // another thread
  [New Thread 0x7ffff67d5700 (LWP 2426)]  // another thread
  Połączono.
  [New Thread 0x7ffff5fd4700 (LWP 2529)]  // parent thread
  [New Thread 0x7ffff57d3700 (LWP 2530)]  // child thread
  
  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7ffff57d3700 (LWP 2530)]
  0x00007ffff7bcb1c0 in sem_post () from /lib/x86_64-linux-gnu/libpthread.so.0
  </code></pre>
  
  <p>What can be a reason of this segfault when I call <code>sem_post()</code>? Maybe should I open by name semafore in child thread with some other method than <code>sem_open()</code>?</p>