Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for not unlinking shared memory partition at process termination #339

Closed
bernhard-thiele opened this issue May 26, 2021 · 0 comments
Assignees
Milestone

Comments

@bernhard-thiele
Copy link
Collaborator

This is Linux specific.

The C destructor function of the SharedMemory object calls shm_unlink(...) and sem_unlink(..).
As an effect it is not possible to open a named shared memory region after a destructor has been called (until eventually all processes using the resource terminate and the memory region gets finally de-allocated and its contents get destroyed).
This is a problem if it needs to be still possible to open a memory region even after one process using the resource terminated.

Common use-case: One (main) process keeps running while other processes which "connect" to the main process are fired up and terminate as needed.

The idea is adding an option to the SharedMemory blocks which prevents unlinking. The default value of cleanup = true results in the current behavior.

image

In a setup of several memory sharing processes, at least one process needs a block which specifies cleanup=true, otherwise shm_unlink(...) and sem_unlink(..) will never be called.

The option has no effect on Windows which (to my understanding) doesn't have a similar issue and simply cleans up after there is no reference left on the file mapping handle or the semaphore handle (or is there an issue, too?).

@bernhard-thiele bernhard-thiele added this to the v2.1.0 milestone May 26, 2021
@bernhard-thiele bernhard-thiele self-assigned this May 26, 2021
bernhard-thiele added a commit to bernhard-thiele/Modelica_DeviceDrivers that referenced this issue May 26, 2021
Linux specific option for not unlinking shared memory partition
at process termination (no effect on Windows).
bernhard-thiele added a commit to bernhard-thiele/Modelica_DeviceDrivers that referenced this issue May 27, 2021
bernhard-thiele added a commit that referenced this issue May 31, 2021
Option `cleanup` for shared memory (closes #339)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant