Skip to content

Enable _posixshmem stdlib module (POSIX shared memory) #306

@ppenna

Description

@ppenna

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

  1. Uncomment in Modules/Setup.stdlib:
    _posixshmem -I$(srcdir)/Modules/_multiprocessing _multiprocessing/posixshmem.c -lrt
    
  2. 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
  3. Required headers: <sys/mman.h>, <fcntl.h>
  4. Link flags: -lrt (may need to verify availability in Nanvix)
  5. Dependency: Requires mmap() support (see mmap module issue)
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions