Skip to content

Memory writes are not seen in another session #8

@saleyn

Description

@saleyn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions