title: User defined signal 1 terminates my POSIX program!
body: <p>I have a program that runs some pthreads, and in every thread there is a <code>connect()</code>, <code>recv()</code> and <code>send()</code>. The problem is that sometimes it suddendly closes the entire program showing the message <code>"User defined signal 1"</code>. It runs in linux, using POSIX threads, in C. The code is like that:</p>
  
  <pre><code>pthread_mutex_t cur_lock;
  int stop = 0;
  
   void SocketsFunction(){
   //..
  connect();
  while(recv()&lt;0)
  {
    //do stuff
  send();
  }
  close();
  return NULL;
  }
  
  void job()
  {
   //..
  while (!stop)
  {
      if (something)
                 //..
      else
      {
          stop = 1;
          break;
      }
  
      pthread_mutex_unlock(&amp;cur_lock);
  
      SocketsFunction();
  
      pthread_mutex_lock(&amp;cur_lock);
  }
  
  pthread_mutex_unlock(&amp;cur_lock);
  
  return NULL;
  }
  
  main(){
  //..
   pthread_mutex_init(&amp;cur_lock, NULL);
  //..
   for(i = 0; i &lt; 30; ++i)
      pthread_create(&amp;pID, NULL, job, NULL);
  
   //..
  }
  </code></pre>