emmap icon indicating copy to clipboard operation
emmap copied to clipboard

Memory writes are not seen in another session

Open saleyn opened this issue 9 years ago • 0 comments

Have you tried concurrent access to the memory mapped file from two shells?

43> os:cmd("cat /dev/shm/test").
"3\n1\n7\n8\n4\n5\n"
44> f(Mem), {ok, Mem} = emmap:open("/dev/shm/test", [read, write, shared, nolock, nocache]).
{ok,{file_descriptor,emmap,<<>>}}
45> f(Bin), {ok, Bin} = emmap:pread(Mem, 0, 12).                                         
{ok,<<"3\n1\n7\n8\n4\n5\n">>}
46> emmap:pwrite(Mem, 0, <<"5">>).                                                       
ok 
47> f(Bin), {ok, Bin} = emmap:pread(Mem, 0, 12).
{ok,<<"5\n1\n7\n8\n4\n5\n">>}

This seems fine - we write "5" on the first position, and it gets updated. Now open this file in another shell:

55> f(Mem), {ok, Mem} = emmap:open("/dev/shm/test", [read, shared, direct, nocache, nolock]).
{ok,{file_descriptor,emmap,<<>>}}
56> f(Bin), {ok, Bin} = emmap:pread(Mem, 0, 12).                                         
{ok,<<"3\n1\n7\n8\n4\n5\n">>}
57> f(Bin), {ok, Bin} = emmap:pread(Mem, 0, 12).                                         
{ok,<<"3\n1\n7\n8\n4\n5\n">>}

So, this doesn't look like the write is visible in another process reading the file. Am I not using the API correctly?

saleyn avatar Dec 18 '14 05:12 saleyn