Authors:
Blaž Rojc
and
Matjaž Depolli
Affiliation:
Jožef Stefan Institute, Jamova cesta 39, 1000 Ljubljana, Slovenia
Keyword(s):
C++, Virtual Memory, Container, Parallel Programming, Efficiency.
Abstract:
Thread safety is required for shared data structures in shared-memory parallel approaches, but cannot be done
efficiently for standard C++ containers with continuous memory storage, such as std::vector. Dynamically
resizing such a container may cause pointer and reference invalidation and therefore cannot be done in parallel
environments without exclusive access protection to the container. We present a thread-safe no-copy resizable
C++ container class that can be used to store shared data among threads of a program on a shared-memory
system. The container relies on the virtual memory controller to handle allocation as needed during execution. A block of memory of almost arbitrary size can be allocated, which is only mapped to physical memory
during the first access, providing hardware-level thread blocking. All synchronization costs are already included in the operating system memory management, so using the container in parallel environment incurs
no additional costs. As a b
onus, references and pointers to elements of the container work as expected even
after the container is resized. The implementation is not general however, and relies on the specifics of the
operating system and computer architecture. Memory overhead can be high as the allocations are bound to the
granularity of the virtual memory system.
(More)