title: flock(), then fgets(): low-level locks, then stdio read/write library functions. Is it possible?
body: <p>I'm writing a server web. </p>
  
  <p>Each connection is served by a separate thread, so <strong>I don't know in advance the number of threads</strong>.</p>
  
  <p>There are also a group of text files (don't know the number, too), and each thread can read/write on each file.</p>
  
  <p>A file can be written by just one thread a time, but different threads can write on different files at the same time.</p>
  
  <p>If a file is read by one or more threads (reads can be concurrent), no thread can write on THAT file.</p>
  
  <p>Now, I noticed this (<a href="https://stackoverflow.com/questions/4998778/thread-safe-multi-file-writing">Thread safe multi-file writing</a>) solution, but I'd like also to use functions as fgets(), for example.</p>
  
  <p>So, can I <em>flock()</em> a file, and then use a fgets() or another stdio read/write library function?</p>