| > You weren't asking, you were saying it wasn't necessary, which you did in the sentence right before this one: quoting my OP: " Why do you need lockless atomic updates to a file-backed memory area? Genuinely curious. " . Dude. > it seems now you were making claims without much behind them, which is disappointing. Well thank you very much. I get the feeling we might just be talking about the same thing. Or we might be not, I'm not sure. > How do you have two processes writing to the same place in memory without memory mapping a file? > You can't write outside your own memory from a process with normal permissions so how do you share memory with another process? For example on Linux, use shm_open() + mmap(). This is just an example, and granted it uses a file-like API (shared memory objects show up on /dev/shm on a typical Linux) but it is not "file-backed" (I meant disk backed and this might be the misunderstanding) and in particular it's certainly not mapping the database file. It's just one way on one OS to map the same physical memory into different processes' address spaces. If this example approach is "file-backed" to you, then so be it but I think you have willfully misread my comments up to here. #include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
int main(int argc, const char **argv)
{
int fd = shm_open("/TESTOBJECT", O_CREAT | O_RDWR, 0664);
if (fd == -1)
{
perror("shm_open()");
exit(1);
}
if (ftruncate(fd, 4) != 0)
{
perror("ftruncate()");
exit(1);
}
void *mapping = mmap(NULL, 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (mapping == MAP_FAILED)
{
perror("mmap()");
exit(1);
}
volatile int32_t *ptr = mapping;
for (;;)
{
printf("%d\n", (int) *ptr);
if (argc > 1)
*ptr = rand();
sleep(1);
}
return 0;
}
|
You kept making the same claim and I asked you to explain it, then you just made the same claim again.
shm_open("/TESTOBJECT"
That's a file path. Maybe you just wanted to bait an argument by not explaining yourself.