title: if using shared memory, are there still advantages for processes over threading?
body: <p>I have written a Linux application in which the main 'consumer' process forks off a bunch of 'reader' processes (~16) which read data from the disk and pass it to the 'consumer' for display.  The data is passed over a socket which was created before the fork using socketpair.</p>
  
  <p>I originally wrote it with this process boundary for 3 reasons:</p>
  
  <ol>
  <li><p>The consumer process has real-time constraints, so I wanted to avoid any memory allocations in the consumer.  The readers are free to allocate memory as they wish, or even be written in another language (e.g. with garbage collection), and this doesn't interrupt the consumer, which has FIFO priority.  Also, disk access or other IO in the reader process won't interrupt the consumer.  I figured that with threads I couldn't get such guarantees.</p></li>
  <li><p>Using processes will stop me, the programmer, from doing stupid things like using global variables and clobbering other processes' memory.</p></li>
  <li><p>I figured forking off a bunch of workers would be the best way to utilize multiple CPU architectures, and I figured using processes instead of threads would generally be safer.</p></li>
  </ol>
  
  <p>Not all readers are always active, however, those that are active are constantly sending large amounts of data.  Lately I was thinking that to optimize this by avoiding memory copies associated with writing and reading the socket, it would be nice to just read the data directly into a shared memory buffer (shm_open/mmap).  Then only an index into this shared memory would be passed over the socket, and the consumer would read directly from it before marking it as available again.</p>
  
  <p>Anyways, one of the biggest benefits of processes over threads is to <em>avoid</em> clobbering another thread's memory space.  Do you think that switching to shared memory would destroy any advantages I have in this architecture?  Is there still any advantage to using processes in this context, or should I just switch my application to using threads?</p>