title: Dividing work up between threads? (pthread)
body: <p>I was creating a program to do some maths on some numbers for a school project. Say I have 10 threads but 42 items to process, I want them to process all the items evenly and take on an even amount of jobs. I'm using the POSIX pthread library, I know it's something to do with mutex but I'm not entirely sure.</p>
  
  <p>Here's a simplified example of what I'm doing, however I want to balance the work load out evenly.</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;pthread.h&gt;
  
  int numbers = { 1, 78, 19, 49, 14, 1, 14. 19, 57, 15, 95, 19, 591, 591 };
  
  void* method() {
    for(size_t i = 0; i &lt; 14; i++) {
      printf("%d\n", (numbers[i] * 2));
    }
  }
  
  int main(int argc, char const *argv[]) {
    pthread_t th[10];
    for (size_t i = 0; i &lt; 10; i++) {
      pthread_create(&amp;th[i], NULL, method, NULL);
    }
    return 0;
  }
  </code></pre>