|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
Cross-process shared-memory container for POD-like objects. More...
#include "jh/metax/t_str.h"#include "jh/macros/platform.h"#include "jh/pods/pod_like.h"#include "jh/synchronous/ipc/process_mutex.h"#include "jh/synchronous/ipc/ipc_limits.h"#include <cstring>#include <cerrno>#include <stdexcept>#include <string>#include <functional>#include <sys/mman.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>Go to the source code of this file.
Classes | |
| class | jh::sync::ipc::process_shm_obj< S, T, HighPriv > |
| Cross-process shared-memory container for a single POD-like object. More... | |
Namespaces | |
| namespace | jh::sync |
| Aggregated entry point for synchronization and coordination facilities. | |
| namespace | jh::sync::ipc |
| Synchronous inter-process coordination primitives. | |
Cross-process shared-memory container for POD-like objects.
jh::sync::ipc::process_shm_obj exposes a process-visible, named shared-memory region containing a single POD-like object of type T. All participating processes reference the same mapped storage, coordinated through a pair of inter-process mutexes.
T must satisfy jh::pod::cv_free_pod_like. T is trivially copyable, constructible, destructible, and has standard layout, without const or volatile qualification. T can be directly memory-mapped without invoking constructors or destructors. shm_open() + mmap(). JH_PROCESS_MUTEX_SHARED (0644 or 0666). CreateFileMapping() + MapViewOfFile(). Global\ namespace for inter-process visibility. process_mutex —
protects one-time initialization of the mapped region.
Access mutex: process_mutex<S + ".loc"> — protects all concurrent writes and ensures serialization of modifications.
Both mutexes are created in the same namespace as the shared object. Declaring a
separate process_mutex or process_mutex<S + ".loc"> externally will conflict with this internal synchronization scheme.
instance() to obtain the singleton mapping. lock() to acquire the access mutex before any write. flush_acquire() beforehand to guarantee visibility of the latest writes from other processes. std::lock_guard (RAII style) on lock(). ref() or ptr(). flush_release() or flush_seq() to publish the change. process_counter: it provides the same memory-sharing model but allows arbitrary POD layouts. Users must therefore manually manage synchronization scope and visibility fences.
shm_unlink() for the region, then calls process_mutex<S>::unlink() and process_mutex<S + ".loc">::unlink() to remove both locks.
On Windows, this primitive requires administrator privilege because
named shared objects and events are created under Global\. POSIX platforms impose no such restriction.