Overall mmap coordinate using fcntl locks?

When used mmap()for shared memory (from Linux or other UNIX-like systems) is it possible (and portable) to use functions fcntl()(or flock()or lockf()) to coordinate display access?

Answers to this question SO seems to suggest that it should work.

The idea I have in mind is to have shared memory structured using a process / page map in order to minimize lock conflict. Processes can work with their pages at the same time, and blocking is only required when updating process / page mappings. (Reading access from unregistered pages will require checking the serial number, copying the required data, and then checking that the serial number of this unit has not changed).

Conceptually, each process using this file association will execute mmap(), find a free block in it, get a lock for the process / page area, update it with its purpose, release the lock, and then have a fun start with its Work. Any process could look for stale comparisons (using kill()zero as a signal) and clear the display of the process / page table.

(In rough, general terms, I play with a producer / consumer processor using shared memory from Python via Linux, I would like the solution to be portable to BSD and other programming languages ​​- for so long as support mmap()and necessary interfaces for fcntl(), flock()or lockf().me I would also be interested in the psuedo-code showing how we can measure lock contention and detect any synchronization failures I know that multi-threading and multiprocessing with their respective objects. Queue()- The easiest way to implement a model of production / require Python I).

+3
source share
1 answer

, , , . , ​​( fcntl, flock lockf ), , -, , , . , , , , , , , , , .

- C, - . , , gcc , :

http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html

Python, __sync_lock_test_and_set (...) __sync_lock_release (...), , . .

, pthread , . , C, Python.

+1

Source: https://habr.com/ru/post/1744846/


All Articles