CS510 Advanced Topics in Concurrency

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Hazard Pointers: Safe Memory Reclamation of Lock-Free Objects
Wait-Free Queues with Multiple Enqueuers and Dequeuers
Ceng-112 Data Structures I Chapter 5 Queues.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects
CS252: Systems Programming Ninghui Li Program Interview Questions.
Maged M. Michael, “Hazard Pointers: Safe Memory Reclamation for Lock- Free Objects” Presentation Robert T. Bauer.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
CS Data Structures II Review COSC 2006 April 14, 2017
Scalable Synchronous Queues By William N. Scherer III, Doug Lea, and Michael L. Scott Presented by Ran Isenberg.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
Introduction to Lock-free Data-structures and algorithms Micah J Best May 14/09.
Simple, Fast, and Practical Non- Blocking and Blocking Concurrent Queue Algorithms Presenter: Jim Santmyer By: Maged M. Micheal Michael L. Scott Department.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
Simple, Fast and Practical Non- Blocking and Blocking Concurrent Queue Algorithms Maged M. Michael & Michael L. Scott Presented by Ahmed Badran.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
An example demonstrating the ABA problem Xinyu Feng University of Science and Technology of China.
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
Review 1 Introduction Representation of Linear Array In Memory Operations on linear Arrays Traverse Insert Delete Example.
Chapter 8 Data Abstractions Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Queues.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects Maged M. Michael Presented by Abdulai Sei.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
CS510 Concurrent Systems Jonathan Walpole. A Methodology for Implementing Highly Concurrent Data Objects.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
Linear Data Structures
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects MAGED M. MICHAEL PRESENTED BY NURIT MOSCOVICI ADVANCED TOPICS IN CONCURRENT PROGRAMMING,
CS510 Concurrent Systems Tyler Fetters. A Methodology for Implementing Highly Concurrent Data Objects.
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
UNIT-II Topics to be covered Singly linked list Circular linked list
Review Array Array Elements Accessing array elements
Stacks and Queues Chapter 4.
Week 4 - Friday CS221.
Hazard Pointers C++ Memory Ordering Issues
Håkan Sundell Philippas Tsigas
Department of Computer Science, University of Rochester
Data Structures and Algorithms
Linked lists.
Stacks and Queues.
Queues Queues Queues.
Joint work with Yong Li, Xinyu Feng, Zhong Shao and Yu Zhang
Stack and Queue APURBO DATTA.
Distributed Algorithms (22903)
Distributed Algorithms (22903)
A Lock-Free Algorithm for Concurrent Bags
CS510 Concurrent Systems Jonathan Walpole.
Distributed Algorithms (22903)
Anders Gidenstam Håkan Sundell Philippas Tsigas
Pointers and Linked Lists
Concurrent Data Structures Concurrent Algorithms 2016
Arrays and Linked Lists
CS510 Concurrent Systems Jonathan Walpole.
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
CS510 - Portland State University
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Data Structures and Algorithms
Data structures.
Multicore programming
CS510 Concurrent Systems Jonathan Walpole.
Stacks, Queues, and Deques
CSCS-200 Data Structure and Algorithms
Linked lists.
Presentation transcript:

CS510 Advanced Topics in Concurrency Jonathan Walpole

Hazard Pointers: Safe Memory Reclamation of Lock-Free Objects Maged M. Michael

The Problem - Lock-free algorithms assume that threads can operate on any object at any time - Freeing memory could break this assumption - How can we free memory of deleted nodes in a safe and lock-free manner?

Prior Work - No reuse Recycling of constant static storage Type safe memory Reference counts with DCAS or CAS2

Goals of Hazard Pointers Readers inform writers of references they hold Bound the number of unreclaimed objects Tolerance for thread failures (wait-free) No special hardware or kernel support needed Suitable for user or kernel use

Hazard Pointers Each thread has a set of pointers that only it writes, but other threads can read Each pointer is either null or points to an object the thread is currently using Before accessing any dynamic object a thread must first store a pointer to it in its list Thread 0 1 2 … n Objects

Retired List Each thread also has a list of nodes it has deleted and would like to free When the length of this list reaches R, the thread scans the hazard pointer lists of all other threads to see if its safe to free any of its nodes. RetNod HP – Thread 2 HP – Thread 3 Thread 1

The ABA Problem Process 1 has a copy of a pointer to Object x Process 2 deletes object x, frees its memory, and reuses the same memory to create a new object y Process 1 applies CAS on the address of object x which is the same as that of object y The CAS succeeds but the object has changed! Process 1 Process 2 Pointer P Pointer P Y X Object

ABA Problem Solved Process 1 has a hazard pointer to object x Process 2 deletes object x and moves object x to its retired nodes list Process 1 can still safely access object x Hazard Pointer disallows freeing the memory and hence reuse of the same memory The ABA problem cannot occur with Hazard Pointers Process 1 Process 2 Retired Nodes List Hazard Pointers X Object

Hazard Pointer Types

Retiring Nodes

Lock Free Dequeue Dequeue : DataType(){ while true { 4: h <- Head; 4a: *hp0 <- h; 4b: if (Head != h) continue; t <- Tail; 5: next <- h.next; *hp1 <- next; 6: if(Head != h) continue; 7: if(next == null) return EMPTY; if(h==t){ CAS(&Tail , t ,next);continue; } data <- next.Data ; 8: if CAS(&Head , h , next) break; 9: RetireNode(h); return data; Record Hazard Pointer for h What if h was removed b/w 4 & 4a? Access Hazard ! What if h was freed by some thread ? ABA Hazard ! What if Head is pointing to some reincarnation of h? ABA hazard on t ! Access Hazard using next ! ABA hazard on h !

Queues

Lock Free Stack Push 1: node <-NewNode(); Intialising the new node Push(data:DataType) { 1: node <-NewNode(); 2: node.Data <- data ; while true { 3: t <- Top ; 4: node.Next <- t ; 5: if CAS(&Top ,t ,node) return; } Intialising the new node Not an Accces Hazard !! Not ABA Hazard as change of Top does not corrupt the Stack. !!

Lock Free Stack Pop Pop() : DataType { While true { 6: t <- Top; 7: if (t == null) return EMPTY; 7a: *hp <- t ; 7b: If (Top != t) continue; 8: next <- t.Next; 9: if CAS (&Top , t ,next) break; } 10: data <- t.Data ; 10a: RetireNode(t) ; 11: return data; Access Hazard on t ! ABA Hazard on t!

Performance (Queues)

Conclusions Safe memory reclamation Solves ABA problem Wait-free if the original algorithm is wait-free Reasonable performance? readers must now write and these writes require memory barriers!

Stacks