0

When you use System V shared memory in Linux, you are supposed to use proper locking and synchronization (using sysv semaphores for example) so the code doesn't break when different threads/processes try to read/write the same segment.

Considering that System V shared memory uses a tmpfs under the hood, if you use files in a tmpfs (instead of memory segments) do you have to provide a synchronization mechanims anyways?
Can't you rely on the file system to provide file read/write synchronization?

GetFree
  • 40,278
  • 18
  • 77
  • 104
  • Concurrent read/write operations on the same file by multiple processes/thread needs to get synchronized too. – hek2mgl Jun 05 '14 at 17:36
  • @hek2mgl, then you are answering the question with a "no". The OS doesn't provide file read/write synchronization – GetFree Jun 05 '14 at 17:39
  • @hek2mgl does the file system API provide synchonization then? `fopen`, `fread` and such, are those functions synchronized? – GetFree Jun 05 '14 at 17:44
  • `flock()` is meant for that. check `man 2 flock`. However, locks are just advisory, meaning other processes can ignore them. – hek2mgl Jun 05 '14 at 17:46
  • I had the impression that using files the synchronization would be easier since you don't need locking when reading, just when writing. – GetFree Jun 05 '14 at 18:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55157/discussion-between-hek2mgl-and-getfree). – hek2mgl Jun 05 '14 at 18:26

0 Answers0