title: Frustrated with my Program Hanging on Return with Waiting Channel of futex_wait_queue_me
body: <p>I'm working on a server-based project.  Basically, when the server starts, it needs to bind a socket port (say 1935).</p>
  
  <p>My problem is, if another instance of my program is running, that is, the socket port 1935 is being used, then a new instance of my program will hang on my main() return.</p>
  
  <p>The Error info:</p>
  
  <pre><code>Error starting server: SocketException: in Socket::bind: ADDRINUSE
  </code></pre>
  
  <p>When error occurs, my program logic will try to <code>return -1</code>.  Before the program exits, the <code>return -1</code> will first free system resource, the specific line that causes the hanging is:</p>
  
  <pre><code>pthread_join ( tid_, 0 )
  </code></pre>
  
  <p>And from System Monitor (<code>gnome-system-monitor</code>), I can see:</p>
  
  <pre><code>Process Name  | Status   | % CPU | Nice | ID    | Memory    | Waiting Channel
  MyProgramName | Sleeping |   0   |  0   | 28573 | 300.0 KiB | futex_wait_queue_me
  </code></pre>
  
  <p>The multithreading part of my project was written by someone else, and there is no documentation.  So I'm kind of getting stuck here.</p>
  
  <p>Please help me out.</p>
  
  <p>If you need more information, please let me know.  I will try my best to add.</p>
  
  <p>And here is my main() logic:</p>
  
  <pre><code>MyServer server(host, port); // When `return -1` is called, this line will eventually call `pthread_join (tid, 0)`
  try
  {
      server.init(config);
  }
  catch (const MyException&amp; e)
  {
      DebugUtils::Error(boost::format("Error initializing server: %1% [%2%].")
                        % e.what() % e.GeneralMessage);
      return -1;
  }
  catch (const std::exception&amp; e)
  {
      DebugUtils::Error(boost::format("Error initializing server: %1%.")
                        % e.what());
      return -1;
  }
  catch (...)
  {
      DebugUtils::Error("Unknown error initializing server.");
      return -1;
  }
  
  try
  {
      server.start();
  }
  catch (const MyException&amp; e)
  {
      DebugUtils::Error(boost::format("Error starting server: %1% [%2%].")
                        % e.what() % e.GeneralMessage);
      return -1;
  }
  catch (const std::exception&amp; e)
  {
      DebugUtils::Error(boost::format("Error starting server: %1%.")
                        % e.what()); // This line output the error info
      return -1; // This line will first free the resource, so it will call the destructor of MyServer on the first line in this code snippet.
  }
  catch (...)
  {
      DebugUtils::Error("Unknown error starting server.");
      return -1;
  }
  </code></pre>
  
  <p>Peter</p>