Private Means Private
Two processes run this on the same file to bump a shared counter. Both exit cleanly, msync returns 0, and the counter in the file is unchanged.
int fd = open("counts.bin", O_RDWR);
uint64_t *m = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_PRIVATE, fd, 0);
m[0] += 1;
msync(m, 4096, MS_SYNC);
munmap(m, 4096);
close(fd);
Which single change makes the increment reach the file?
Sign in to answer questions and track your progress
Sign In