Blocking freedom / atomic operations through 2 processes instead of threads

I share some data across several processes using shared memory; To achieve synchronization, I use inter process mutexes.

My question is this: is it possible to use locked AND / OR data structures to perform faster synchronization without using mutexes between the two processes?

If you do not know what is the main reason for this?

They are used only to synchronize threads of the same process. Are these concepts transferable to processes? If not, do you know any faster way to share / synchronize data between processes?

+7
source share
2 answers

Are these concepts also portable for processes?

Yes, atomic operations are universal for both threads and processes, IIF, used atomically, is shared.

The atomic operation is a specific instruction of the processor itself and does not know anything about threads or processes, it is just a whole or indivisible (indivisible) set of actions (reading, comparison, storage) with a low-level hardware implementation.

So, you can configure shared memory between processes and put atom_t in it.

blocking

Yes, if lock-free is implemented only with atomic. (He must)

data structures

You must verify that shared memory maps to the same address in both processes when used to store pointers (in data structures).

If the memory is mapped to a different address, the pointers will be split into another process. In this case, you need to use relative addresses and perform a simple memory transfer.

inter process mutexes

And I have to say that glibc> 2.4 (NPTL) uses futex in conjunction with atomic operations for unsupported locking (for general mutexes Process = inter process mutexes). So, you are already using atomic operations in shared memory.

+8
source

In x86 with NPTL, most synchronization primitives have only one interconnected operation with a full memory barrier as their fast path. Since x86 platforms actually don't have anything easier, this is the very best you can do. If existing atomic operations do not do exactly what you need to do, there will be no increase in performance to return the cost of using a semantically lighter primitive.

+2
source

All Articles