SRW lock in shared memory

Can SRW Locks be used between processes when shared?

Their memory size only seems to be the only pointer, but I can not find the documentation of what actually happens in the background when locking.

I would like, if possible, to avoid explicit kernel mutexes, but it starts to look like I'm entering an undefined behavior area.

+6
source share
2 answers

SRW locks cannot be shared between processes. This is implied by a pointed omission in the first sentence of the documentation which states

Blocking Slim reader / writer (SRW) allows threads of a single process to access shared resources ...

These objects make use of the fact that they are used as part of a single process. For example, threads waiting to enter a lock are tracked as a linked list. This list of pending threads should obviously be stored somewhere outside of SRWLock, since SRWLock is only the size of one pointer, and you cannot put a list of 10 threads inside one pointer. This linked list will not be available to other processes.

+5
source

SRWs are user objects (like critical sections), not kernel objects. They cannot be shared between processes. They have no name.

SRWs are implemented for performance - they are faster than critical sections (and obviously faster than mutexes). They do not allow recursive locks (CS and mutexes are allowed).

Since they are implemented for speed and performance, they are intended for only one access to the process. Placing the SRW handle in shared memory will not make it available for another process to start using it. SRW is just an opaque handle to internal implementation. When a handle is mapped by a process, it is at the same process boundary — cannot be used by another process. Since they are not kernel objects, overlay control is also not possible.

0
source

All Articles