A Lock-Free Dynamically Resizable Array Damian Dechev 1 Peter - - PowerPoint PPT Presentation

a lock free dynamically resizable array
SMART_READER_LITE
LIVE PREVIEW

A Lock-Free Dynamically Resizable Array Damian Dechev 1 Peter - - PowerPoint PPT Presentation

A Lock-Free Dynamically Resizable Array Damian Dechev 1 Peter Pirkelbauer 1 Bjarne Stroustrup 1 , 2 1 Department of Computer Science Texas A&M University 2 AT&T Research OPODIS, December 2006 Parasol Lab (Texas A&M) Lock-Free Dynamic


slide-1
SLIDE 1

A Lock-Free Dynamically Resizable Array

Damian Dechev1 Peter Pirkelbauer1 Bjarne Stroustrup1,2

1Department of Computer Science

Texas A&M University

2AT&T Research

OPODIS, December 2006

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 1 / 18

slide-2
SLIDE 2

Overview

A first design of a lock-free [Fra04] dynamically resizable array for C++ Similar to STL vector [Str00]. Dynamic memory management Constant-time random access

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 2 / 18

slide-3
SLIDE 3

Motivation

STL containers used with locks

◮ Performance problems (low parallelism) ◮ Safety problems (deadlock, livelock, priority inversion)

Application Areas

◮ Autonomous Real-Time Systems ◮ Mission Data Systems at JPL ◮ Distributed Parallel Containers [AJR+01] Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 3 / 18

slide-4
SLIDE 4

Design Principles

Portability

◮ word-size compare and swap (CAS)

Efficiency

◮ Minimal Overhead ◮ Wait-free [Fra04] random access read and write

Linearizable operations [HW90] Lock-free memory allocation and management

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 4 / 18

slide-5
SLIDE 5

std::vector goes lockfree

Complexity of operation:

Operation modified Location resize all entries push_back size, tail pop_back size write

  • ne element

read none size none

resize: relocates all elements and alters the capacity

◮ Two-level array

push_back: modifies size and an element

◮ Barnes-style announcement [Bar93]

element-size: pointer semantics

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 5 / 18

slide-6
SLIDE 6

lockfree::vector - interface

Semantics Assumes sequential semantics

◮ vec.back(); vec.pop_back();

pop_back: removes the last element

◮ returns and removes the last element Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 6 / 18

slide-7
SLIDE 7

lockfree::vector - push_back

Vector +desc +memory: T*[32] T:class Descriptor +size: size_t = 2 +writeop T:class

...

1 31 a b

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 7 / 18

slide-8
SLIDE 8

lockfree::vector - push_back (cont’d)

Vector +desc +memory: T*[32] T:class Descriptor +size: size_t = 2 +writeop T:class

...

1 31 a b

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 8 / 18

slide-9
SLIDE 9

lockfree::vector - push_back (cont’d)

Vector +desc +memory: T*[32] T:class Descriptor +size: size_t = 2 +writeop T:class

...

1 31 a b

WriteOp +pending: bool = true +value_old: T = NULL +pos: T* +value_new: T = c T:class Descriptor +size: size_t = 3 +writeop T:class Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 9 / 18

slide-10
SLIDE 10

lockfree::vector - push_back (cont’d)

Vector +desc +memory: T*[32] T:class Descriptor +size: size_t = 2 +writeop T:class

...

1 31 a b

WriteOp +pending: bool = true +value_old: T = NULL +pos: T* +value_new: T = c T:class Descriptor +size: size_t = 3 +writeop T:class Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 10 / 18

slide-11
SLIDE 11

lockfree::vector - push_back (cont’d)

Vector +desc +memory: T*[32] T:class

...

1 31 a b

WriteOp +pending: bool = false +value_old: T = NULL +pos: T* +value_new: T = c T:class Descriptor +size: size_t = 3 +writeop T:class

c

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 11 / 18

slide-12
SLIDE 12

lockfree::vector - Operations

Operations Descriptor (Desc) Complexity push_back Vec × Elem → void Desct → Desct+1 O(1) × cong. pop_back Vec → Elem Desct → Desct+1 O(1) × cong. resize Vec × size_t → Vec Desct → Desct O(1) read Vec × size_t → Elem Desct → Desct O(1) write Vec × size_t × Elem → Vec Desct → Desct O(1) size Vec → size_t Desct → Desct O(1)

Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 12 / 18

slide-13
SLIDE 13

lockfree::vector - Performance (Dual-Core)

Intel 1.83GHz Dual Core

◮ 512MB shared RAM, 2MB shared L2 cache, MAC OS X Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 13 / 18

slide-14
SLIDE 14

lockfree::vector - Performance (4xDual-Core)

AMD 2.2GHZ Quad Dual Core Opteron

◮ 4GB shared RAM, 1MB L2 cache (per die), MS Windows 2003 Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 14 / 18

slide-15
SLIDE 15

lockfree::vector - ABA Problem

Common to all CAS-based systems General Solution:

◮ version counter Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 15 / 18

slide-16
SLIDE 16

lockfree::vector - ABA Problem (cont’d)

Prevention: store unqiue elements Solution:

◮ Object Reclamation Scheme ⋆ Pass The Buck (Herlihy et al. [HLMM05]) ⋆ Hazard Pointers (Michael [Mic04]) ◮ Implement Value Semantics Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 16 / 18

slide-17
SLIDE 17

Conclusion and Future Work

First practical and portable design of a lock-free vector Future Work

◮ Integrate effective ABA solution ◮ Refine lockfree::vector interfaces Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 17 / 18

slide-18
SLIDE 18

References I

Ping An, Alin Jula, Silvius Rus, Steven Saunders, Tim Smith, Gabriel Tanase, Nathan Thomas, Nancy Amato, and Lawrence Rauchwerger. STAPL: A Standard Template Adaptive Parallel C++ Library. In LCPC ’01, pages 193–208, Cumberland Falls, Kentucky, Aug 2001. Greg Barnes. A method for implementing lock-free shared-data structures. In SPAA ’93: Proceedings of the fifth annual ACM symposium on Parallel algorithms and architectures, pages 261–270, New York, NY, USA, 1993. ACM Press. Keir Fraser. Practical lock-freedom. Technical Report UCAM-CL-TR-579, University of Cambridge, Computer Laboratory, February 2004. Maurice Herlihy, Victor Luchangco, Paul Martin, and Mark Moir. Nonblocking memory management support for dynamic-sized data structures. ACM Trans. Comput. Syst., 23(2):146–196, 2005. Maurice P . Herlihy and Jeannette M. Wing. Linearizability: a correctness condition for concurrent objects. ACM Trans. Program. Lang. Syst., 12(3):463–492, 1990. Maged M. Michael. Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects. IEEE Trans. Parallel Distrib. Syst., 15(6):491–504, 2004. Bjarne Stroustrup. The C++ Programming Language. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2000. Parasol Lab (Texas A&M) Lock-Free Dynamic Array OPODIS, December 2006 18 / 18