operating-systems concurrency

Definition

Shared Memory

Shared memory is an inter-process communication (IPC) mechanism where a region of physical memory is mapped into the address space of two or more processes. This allows the processes to communicate by reading and writing to the same memory locations.

Shared memory is typically the fastest form of IPC because it avoids the overhead of copying data between process address spaces and the kernel.

Mechanism

  1. Creation: One process creates a shared memory segment.
  2. Mapping: Other processes attach (map) this segment into their own virtual address space.
  3. Access: Processes read and write to the memory as if it were local data.

Synchronisation Requirement

Because multiple processes can access the shared memory simultaneously, the operating system does not provide automatic protection against concurrent access. It is the responsibility of the application programmer to use synchronisation primitives to maintain consistency:

Failure to synchronise properly leads to race conditions.