title: compare array with multiple thread using pThread in C
body: <p>I have some difficulties in understanding multiple thread. Here is the situation: </p>
  
  <p>I am going to select some integers from an array and store them into another array with some conditions. The conditions is quite complicated, basically it's a huge set of comparison between array[i] and all others array[not i]. Let's called it checkCondition();</p>
  
  <p>First, I create the pthread. Here is my code, noted that dataPackage is a struct containing the array.</p>
  
  <pre><code>for(int i = 0; i &lt; thread_number; i++){
      if(pthread_create(&amp;tid, NULL, checkPermissible, &amp;dataPackage) != 0){
          perror("Error occurs when creating thread!!!\n");
          exit(EXIT_FAILURE);
      }
  }
  
  for(int i = 0; i &lt; thread_number; i++){
      pthread_join(tid, NULL);
  }
  </code></pre>
  
  <p>Here is the content of checkPermissible()</p>
  
  <pre><code>void* checkPermissible(void* content){
      readThread *dataPackage = content;
  
      for(int i = 0; i &lt; (*dataPackage).arrayLength; i++){
          if(checkCondition()){
              pthread_mutex_lock(&amp;mutex);
              insert(array[i], (*dataPackage).result);
              pthread_mutex_unlock(&amp;mutex);
              //if condition true, insert it into result(a pointer)
              //mutex avoid different thread insert the value at the same time
          }
      }
  
      pthread_exit(NULL);
  }
  </code></pre>
  
  <p>However, It would not have any difference if I'm not using pThread way to do this. How to I implement checkPermissible() in order to bring out the advantage of multiple thread? I quite confused about this stuff. </p>
  
  <p>My idea is, dividing the array into noOfThread in each Thread. For example, I have an array[20] and 4 thread,</p>
  
  <pre><code>Thread 1: compute checkCondition with array[0] to array[4]
  Thread 2: compute checkCondition with array[5] to array[9]
  Thread 3: compute checkCondition with array[10] to array[14]
  Thread 4: compute checkCondition with array[15] to array[19]
  </code></pre>
  
  <p>Something like that, in which I don't know how to achieve.</p>