title: use array of pthread conditional variable inside a struct
body: <p>I am trying to create pthread example which will create pthread conditional and pthread mutex inside a struct and then i will use that conditional and mutex variable inside a fucntion.</p>
  
  <p>My source is:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;assert.h&gt;
  
  struct SubObj {
    //pthread_mutex_t *mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
    //pthread_cond_t *cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
    pthread_cond_t *cond;
    pthread_mutex_t *mutex;
  } subobj;
  
  const size_t NUMTHREADS = 4;
  
  int done = 0;
  
  void* ThreadEntry(void* id) 
  {
    const int myid = (long) id;
    const int workloops = 200;
  
    printf("[thread %d] done is now %d. Signalling cond.\n", myid, done);
  
    for (int i = 0; i &lt; workloops; i++) 
    {
        printf("[thread %d] working (%d/%d)\n", myid, i, workloops);
    }
  
    pthread_mutex_lock(&amp;subobj.mutex);
    done++;
    pthread_mutex_unlock(&amp;subobj.mutex);
    pthread_cond_signal(&amp;subobj.cond);
  
    return NULL;
  }
  
  int main(int argc, char** argv) 
  {
    subobj.mutex = PTHREAD_MUTEX_INITIALIZER;
    subobj.cond = PTHREAD_COND_INITIALIZER;
  
    pthread_t threads[NUMTHREADS];
  
    for (int t = 0; t &lt; NUMTHREADS; t++)
        pthread_create(&amp;threads[t], NULL, ThreadEntry, (void*) (long) t);
  
    pthread_mutex_lock(&amp;subobj.mutex);
  
    while (done &lt; NUMTHREADS) 
    {
        printf("[thread main] done is %d which is &lt; %d so waiting on cond\n",
              done, (int) NUMTHREADS);
  
        pthread_cond_wait(&amp;subobj.cond, &amp;subobj.mutex);
    }
  
    printf("[thread main] done == %d so everyone is done\n", (int) NUMTHREADS);
  
    pthread_mutex_unlock(&amp;subobj.mutex);
  
    return 0;
  }
  </code></pre>
  
  <p>But after compiling this source, it gives me error. Really passing some bad time on this. </p>
  
  <pre><code>[ Compiling source file (condInStruct.c) to bitcode 
  (../obj/condInStruct.c.prof.bc) ]
  condInStruct.c:49:17: error: expected expression
      subobj.mutex = PTHREAD_MUTEX_INITIALIZER;
                     ^
  /usr/include/pthread.h:87:3: note: expanded from macro ' 
  
   PTHREAD_MUTEX_INITIALIZER'
    { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } }
    ^
   condInStruct.c:50:16: error: expected expression
      subobj.cond = PTHREAD_COND_INITIALIZER;
                    ^
  /usr/include/pthread.h:186:34: note: expanded from macro 
  'PTHREAD_COND_INITIALIZER'
  #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
  </code></pre>
  
  <p>What is the best approach to create pthead sync objects array inside struct and then use this in the fucntions.</p>
  
  <p>Thanks in advance.</p>