title: Synchronization of acces to shared memory
body: <p>i have shared memory, x writers, y readers, one parent process. Writers have exclusive access, so one writer can write and other readers and writers must wait. Multiple readers can read parallel. Priority is on writers, so for example if 3 readers are reading and one writer want write to that shared memory, then when those 3 readers finish their job, no more readers can read and writer can write. I dont know how to implement it through semaphores, because readers can read parallel, so next code will not work, because then all readers will be waiting in that semaphore.</p>
  
  <pre><code>//reader
  if(isWriterActive())
  {
     sem_wait(semReaderStop);
  } 
  
  //writer
  sem_wait(semReaderStop());
  .
  .
  sem_post(semReaderStop());
  </code></pre>
  
  <p>I think something like this is not good, because it is not blocking.</p>
  
  <pre><code>//readers doJob
  if(isWriterActive())
  {
      return E_WRITER_ACTIVE;
  }
  
  while(doJob()==E_WRITER_ACTIVE);
  </code></pre>