title: C++ sleep pthread conflict
body: <p>I am writing a code about the deadlocks and their detection, i use eclipse Juno C/C++ on Ubuntu 12.10, 64 bit.
  The problem is when i use </p>
  
  <blockquote>
    <p>sleep(1)</p>
  </blockquote>
  
  <p>, i get this</p>
  
  <blockquote>
    <p>sleep was not declared in this scope</p>
  </blockquote>
  
  <p>when i build the project, i tried to include </p>
  
  <blockquote>
    <p>include &lt; unistd.h></p>
  </blockquote>
  
  <p>, but then all the pthread functions like </p>
  
  <blockquote>
    <p>pthread_join</p>
  </blockquote>
  
  <p>gives me errors like </p>
  
  <blockquote>
    <p>undefined reference to pthread_join</p>
  </blockquote>
  
  <p>, without <strong>#include &lt; unistd.h></strong> such error doesn't show up.</p>
  
  <p>sample code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;iostream&gt;
  #include &lt;semaphore.h&gt;
  #include &lt;queue&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  pthread_mutex_t mutex;
  sem_t sem; //used for writing in the console
  
  .......
  
  void cross(Batman b) {
  // code to check traffic from the right, use counters, condition
  sem_wait(&amp;sem);
  cout &lt;&lt; "BAT " &lt;&lt; b.num &lt;&lt; " from " &lt;&lt; b.direction &lt;&lt; " crossing" &lt;&lt; endl;
  sem_post(&amp;sem);
  sleep(1);
  }
  ........
  </code></pre>
  
  <p>p.s. i followed these instructions to get pthreads working in other project and i did the same for this project 
  <a href="http://blog.asteriosk.gr/2009/02/15/adding-pthread-to-eclipse-for-using-posix-threads/" rel="nofollow">http://blog.asteriosk.gr/2009/02/15/adding-pthread-to-eclipse-for-using-posix-threads/</a></p>
  
  <p>p.s. i am working on this project with a friend and i used the same code he uses and still get those errors, while he doesn't</p>