Nobody can Open this shared memory again! But this shared memory will be removed only when all attached processes exit (or terminate). Careful! Calling this method simultaneously from multiple processes may lead to unlinking another's shared memory! Better use with UP_CREATOR_UNLINKS flag.
| 91 | // Careful! Calling this method simultaneously from multiple processes may lead to unlinking another's shared memory! |
| 92 | // Better use with UP_CREATOR_UNLINKS flag. |
| 93 | bool Unlink(const EUnlinkPolicy up) { |
| 94 | // This method is the only reason to switch from System V shared memory (shmget/shmat/shmdt) to POSIX shared memory: |
| 95 | // using System V shared memory after shmdt is unspecified behavior: smhdt decrements refcount and after its call |
| 96 | // shared memory may be removed (if refcount == 0 && somebody called shmctl(IPC_RMID)) without waiting process to exit! |
| 97 | // But without calling it right after attaching we may have "shared memory leak" after unexpected processes termination. |
| 98 | // In the opposite unlinking POSIX shared memory is like unlinking files - nobody can open it again, but processes |
| 99 | // which already opened it will see no difference. |
| 100 | if (up == UP_FORCE_UNLINK || (IsCreator && up == UP_CREATOR_UNLINKS)) { |
| 101 | Y_ASSERT(!Unlinked && !Guid.IsEmpty()); |
| 102 | Y_ABORT_UNLESS(!Unlinked, "You tried to unlink shared memory twice! Fix your code"); |
| 103 | Unlinked = shm_unlink(ConvertGuidToName(Guid).c_str()); |
| 104 | return Unlinked; |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | const TGUID& GetId() { |
| 110 | return Guid; |
no test coverage detected