title: Synchronization objects in C and its association with structs of data structures
body: <p>I have written some data structures in C like task queue used by thread pool. It is synchronized with mutex and conditional variable objects. 
  I make it like this: </p>
  
  <pre><code>struct task_queue { 
    // some fields
  };
  
  typedef struct task_queue task_queue_t; 
  
  static pthread_mutex_t mutex; 
  static pthread_cond_t cond; 
  
  task_queue_init(task_queue_t **tq);
  task_queue_destroy(task_queue_t *tq); 
  </code></pre>
  
  <p>But now I think that such approach is rather wrong as when I create with <strong>task_queue_init()</strong> several instances of task_queue struct in my program than they will be synchronized by the same pthread_mutex_t, pthread_cond_t objects. I think that I have seen such <strong>static</strong> synchronization objects declarations somewhere previously and I have used it in my code. </p>
  
  <p>My question is to make sure myself that I am planning to do it right way i.e put this synchronization objects always inside this struct task_queue, or other synchronized data structure struct like below: </p>
  
  <pre><code>struct task_queue { 
     // hitherto fields
     pthread_mutex_t mutex;
     pthread_cond_t cond; 
  }
  typedef struct task_queue task_queue_t; 
  
  //and initialize/destroy them in 
  task_queue_init(task_queue_t **tq); 
  task_queue_destroy(task_queue_t *tq); 
  </code></pre>
  
  <p>Maybe I should use pointers to mutex, cond in this struct?</p>