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

Emulate POSIX shared memory behavior on Windows #59

Merged
merged 6 commits into from Mar 18, 2021

Conversation

defiori
Copy link
Contributor

@defiori defiori commented Mar 8, 2021

Shmem currently behaves differently on Windows than Unix. Specifically, Shmem::set_owner has no effect on the underlying memory object on Windows, as the standard Windows shared file mapping doesn't allow persistence. This means that dropping a unique Shmem will destroy the shared memory even when Shmem::is_owner returns false. This clashes with POSIX behaviour, which persists the memory unless shm_unlink() is called and allows reopening even when all handles have previously been closed.

This PR unifies shared memory behaviour on Windows and Unix and adds a test to check for compliance. It follows the C++ Boost implementation of creating a file to back the shared memory which is renamed and marked for deletion when an owning Shmem drops, but persists otherwise. Shmem::set_owner stops being a no-op on Windows and now behaves as expected.

@elast0ny
Copy link
Owner

Hi, thanks a lot for the PR.

I will try to review it and fix the build issues in the next couple of days

@defiori
Copy link
Contributor Author

defiori commented Mar 12, 2021

Sounds good, thanks. The latest commit fixes clippy's complaints on Windows, the remaining build issue isn't specific to this PR.

@elast0ny elast0ny merged commit e3d0d4a into elast0ny:master Mar 18, 2021
@elast0ny
Copy link
Owner

Thanks again for the PR.

I have converted your code to rely on std as much as it could and merged it into master.

I will publish a new version of the crate (0.12.X) in the next couple of days.

Let me know if you spot any issues with my refactoring ;)

@defiori
Copy link
Contributor Author

defiori commented Mar 28, 2021

This looks much cleaner, thanks. I just added one minor nitpick in a comment, otherwise it looks good. Looking forward to v0.12!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants