title: Pthread failed to be created
body: <p>I'm currently working on a homework assignment that uses multiple threads to perform matrix multiplication but I keep getting the error message that all of the pthreads failed to be created. I have put below some of the snipets of code that have to do with allocation space for threads, allocation blocks of work for threads along with pthread_create &amp; pthread_join then the threadMMulti is the function that each thread uses. My error is coming from this piece of code </p>
  
  <pre><code> if (errorCode = pthread_create(&amp;threadHandles[i], NULL, threadMAdd, 
                     &amp;blocksOfWork[i]) != 0) {
        printf("pthread %d failed to be created with error code %d\n", i, errorCode);
  </code></pre>
  
  <p>So from my understanding pthread_create will return 0 if the thread is created so it's obvious that the pthread_create is failing and returning a number other then 0 so the message is displayed, I've looked into the parameters of pthread_create and I just can't seem to find where i'm going wrong. If anyone has any tips or points in the right direction I would appreciate it. </p>
  
  <p>Code Snippets:   </p>
  
  <pre><code>typedef struct {
      int threadId;
      int start_row;
      int end_row;
      int start_col;
      int end_col;
  } BLOCK;
  
  // Generate arrays for threads handles
  threadHandles = (pthread_t *) malloc(numberOfThreads*sizeof(pthread_t));
  blocksOfWork = (BLOCK *) malloc(numberOfThreads*sizeof(BLOCK));
  
  
  // allocate block of work for each thread
  for(i=0; i &lt; numberOfThreads; i++){
      blocksOfWork[i].threadId = i;
      blocksOfWork[i].start_row = i * rows/numberOfThreads;
      if (i == numberOfThreads -1){
          blocksOfWork[i].end_row = rows - 1;
      }
      else{
          blocksOfWork[i].end_row = (i+1)*rows/numberOfThreads -1;
      }
      blocksOfWork[i].start_col = 0;
      blocksOfWork[i].end_col = columns -1;
  }
  for (i=0; i &lt; numberOfThreads; i++) {
      if (errorCode = (pthread_create(&amp;threadHandles[i], NULL, threadMMult, 
                                      &amp;blocksOfWork[i])) != 0) {
          printf("pthread %d failed to be created with error code %d\n", i, errorCode);
      } // end if
  } // end for
  
  for (i=0; i &lt; numberOfThreads; i++) {
      if (errorCode = pthread_join(threadHandles[i], (void **) NULL) != 0) {
          printf("pthread %d failed to be joined with error code %d\n", i, errorCode);
      } // end if
  } // end for
  
  void * threadMMult(void * arg){
      BLOCK * block = (BLOCK *) arg;
      int threadId = block-&gt;threadId;
      int startRow = block-&gt;start_row;
      int endRow = block-&gt;end_row;
      int startCol = block-&gt;start_col;
      int endCol = block-&gt;end_col;
      int i, j, k;
  
      for (int i =startRow; i&lt;=endRow;i++){
          for (int j =startCol; i&lt;=endCol; j++){
              C[i][j] = 0;
              for(int k =0; k&lt;=endCol; k++){
                  C[i][j] += A[i][k]*B[k][j];
              }
          }
      }
  }
  </code></pre>