Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SRW lock in shared memory

Tags:

c++

winapi

Can SRW Locks be used between processes when placed in shared memory?

Their memory footprint only seems to be a single pointer, but I am unable to find documentation on what actually happens in the background when locking.

I would like to avoid kernel mutexes if possible, but it starts to look like I am entering undefined behaviour land.

like image 791
Rick de Water Avatar asked May 24 '16 09:05

Rick de Water


1 Answers

SRW Locks cannot be shared between processes. This is implied by pointed omission in the opening sentence of the documentation that says

Slim reader/writer (SRW) locks enable the threads of a single process to access shared resources...

These objects take advantage of the fact that they are used within a single process. For example, the threads waiting to enter the lock are tracked in the form of a linked list. This list of waiting threads obviously has to be kept somewhere outside the SRWLock, seeing as the SRWLock is only the size of a single pointer, and you can't put a list of 10 threads inside a single pointer. That linked list won't accessible to other processes.

like image 54
Raymond Chen Avatar answered Oct 23 '22 07:10

Raymond Chen