boostorg / boostorg/interprocess

Feature Request: Provide non-throwing methods to open/create shared_memory_object

Offen
#151 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C++
Sterne
185
Forks
131
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

My use case is as follows. I need to synchronize multiple processes or threads initializing a shared memory region. No select process can be considered the "master", so it is not known which of the processes will actually create and initialize the shared memory object. The natural solution would be to construct `shared_memory_object(open_or_create)`, but this introduces a problem that the caller doesn't know whether the shared memory was created or an existing region was opened. This is important to later decide whether the caller should resize the region to the desired size and initialize the contents or try and adopt the existing one. (Testing the region size for 0 is not safe because it introduces a race condition.)

The current API does not provide a way to implement this efficiently. It is possible to implement a loop trying to construct `shared_memory_object(open_only)` or `shared_memory_object(create_only)`, but the constructors throw on failure, which is unnecessary overhead and awkward to use in the caller. Indeed, you have implemented exactly that [here](https://github.com/boostorg/interprocess/blob/e4259fe16804f5a4b179e1c7e69d201bd532d31a/include/boost/interprocess/detail/managed_open_or_create_impl.hpp#L285-L338). It would be better to have a set of methods in `shared_memory_object` that allow to create or open the shared memory and able to report the result without throwing - for example, through an `error_code` argument.

Also, please consider adding a way to create a shared memory segment of a given size. On POSIX, this would allow the aforementioned loop to be implemented in Boost.Interprocess instead of user's code. On Windows, `CreateFileMappingW` already accepts the desired size. This new API would also have to provide a result so that the caller knows whether a new segment was created or not.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start by reading the shared_memory_object API and the referenced managed_open_or_create_impl.hpp code, especially lines 285-338. Determine how non-throwing create/open operations can report whether a segment was created, including a requested size on POSIX and Windows. Done means the API supports the synchronization use case without constructor exceptions and distinguishes creation from opening.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
cpp
Bereich
operating-systems
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.