Summary
Enable the _posixshmem C extension module, which provides POSIX shared memory support for multiprocessing.shared_memory.
Current State
Commented out in Modules/Setup.stdlib:
#_posixshmem _multiprocessing/posixshmem.c
Why Enable It
- Required for
multiprocessing.shared_memory.SharedMemory
- Enables zero-copy IPC between processes via shared memory segments
- Used by data processing and scientific computing workloads
Work Required
- Uncomment in
Modules/Setup.stdlib:
_posixshmem -I$(srcdir)/Modules/_multiprocessing _multiprocessing/posixshmem.c -lrt
- Nanvix POSIX API requirements:
shm_open(name, oflag, mode) — create/open shared memory object
shm_unlink(name) — remove shared memory object
ftruncate(fd, length) — set shared memory size
mmap() / munmap() — map shared memory into address space
- Required headers:
<sys/mman.h>, <fcntl.h>
- Link flags:
-lrt (may need to verify availability in Nanvix)
- Dependency: Requires
mmap() support (see mmap module issue)
- Build and test:
python -c "from multiprocessing import shared_memory; sm = shared_memory.SharedMemory(create=True, size=1024); sm.close(); sm.unlink()"
POSIX API Dependencies
| API |
Purpose |
shm_open() |
Create/open shared memory object |
shm_unlink() |
Remove shared memory object |
ftruncate() |
Set size of shared memory |
mmap() |
Map into address space |
munmap() |
Unmap from address space |
Complexity
High — requires POSIX shared memory and mmap() support in Nanvix.
Source Files
Modules/_multiprocessing/posixshmem.c
Summary
Enable the
_posixshmemC extension module, which provides POSIX shared memory support formultiprocessing.shared_memory.Current State
Commented out in
Modules/Setup.stdlib:Why Enable It
multiprocessing.shared_memory.SharedMemoryWork Required
Modules/Setup.stdlib:shm_open(name, oflag, mode)— create/open shared memory objectshm_unlink(name)— remove shared memory objectftruncate(fd, length)— set shared memory sizemmap()/munmap()— map shared memory into address space<sys/mman.h>,<fcntl.h>-lrt(may need to verify availability in Nanvix)mmap()support (see mmap module issue)python -c "from multiprocessing import shared_memory; sm = shared_memory.SharedMemory(create=True, size=1024); sm.close(); sm.unlink()"POSIX API Dependencies
shm_open()shm_unlink()ftruncate()mmap()munmap()Complexity
High — requires POSIX shared memory and
mmap()support in Nanvix.Source Files
Modules/_multiprocessing/posixshmem.c