title: Passing a two-dimensional array for threaded processing
body: <p>K and THREADS are arbitrarily defined as follows:</p>
  
  <pre><code>#define K 1000
  #define THREADS 2
  </code></pre>
  
  <p>Let's say I'm responsible for doing some stuff with a two-dimensional array called:</p>
  
  <pre><code>long A[K][K];
  </code></pre>
  
  <p>I need to pass this, as well as an integer, to a number of threaded instances of a function, so I make this struct:</p>
  
  <pre><code>typedef struct tdata {
      long *(*C)[K];
      int nt;
  } tdata;
  </code></pre>
  
  <p>I then follow standard procedure for starting POSIX threads and do the following:</p>
  
  <pre><code>void threader(long A[K][K]) {    
      pthread_t p[THREADS];
      tdata d[THREADS];
      int i;
  
      for(i=0;i&lt;THREADS;++i) {
          d[i].nt = i;
          d[i].C = &amp;A;
          pthread_create(&amp;p[i],NULL,func,&amp;d[i]);
          pthread_join(p[i],NULL);
      }
  }
  </code></pre>
  
  <p>And then in my function, I attempt to access the aforementioned array as follows:</p>
  
  <pre><code>void *func(void *arg) {
     tdata *data=arg;
     int a, b;
     ...
     for(a=0; a&lt;K; ++a)
        for(b=0; b&lt;K; ++b)
           long access = (*(data-&gt;C))[a][b];
     ...
     return 0; 
  }
  </code></pre>
  
  <p>What happens is I end up retrieving a few wonky numbers before the program seg faults and dies. My suspicion is that I'm doing something very wrong in regards to passing my array to func. Can anyone give me a clue as to what I should be doing with A[K][K]?</p>