Presentation is loading. Please wait.

Presentation is loading. Please wait.

IMPLEMENTATION OF A NON-BLOCKING QUEUE ALGORITHM

Similar presentations


Presentation on theme: "IMPLEMENTATION OF A NON-BLOCKING QUEUE ALGORITHM"— Presentation transcript:

1 IMPLEMENTATION OF A NON-BLOCKING QUEUE ALGORITHM
Chien-Hua Shann, Ting-Lu Huang and Cheng Chen National Chiao Tung University Nastaran Shafiei 1

2 Outline Algorithm Description Class Diagram Algorithm Implementation
Results 2

3 The Algorithm Finite array, Q Counters, FRONT and REAR
Operations: enqueue, dequeue Elements of the queue 3

4 NonblockingQueue L: int Enqueue Dequeue val: int Thread
Queue: AtomicLongArray REAR: AtomicLong FRONT: AtomicLong getValPart(long item) getRefPart(long item) getQueueItem(int val, int ref) main(String[] args) Enqueue Dequeue val: int Enqueue(int value) void run() void run() Thread

5 Shared Variables Atomic variables java.util.concurrent.atomic
public static AtomicLongArray Queue; public static AtomicLong RAER; public static AtomicLong FRONT; Atomic variables java.util.concurrent.atomic get() and set() Extend the concept of volatile variables compareAndSet() 5

6 Implementation of Array Elements
An Array Element: getCounter(long element) ; 32 bits 32 bits int val int ref 64 bits val ref << ref >> ref

7 Implementation of Array Elements
getQueueValue(long element) getQueueEntryType(int val, int ref) val ref >> val val << val + ref = val ref

8 Implementation of Enqueue.run()
Make private copies using get(): rear = REAR.get(); front = FRONT.get(); x = Queue.get ((int)rear % L); Check conditions: rear == REAR.get() rear != FRONT.get() + L 8

9 Implementation of Enqueue.run()
Check the content of the array element: Empty - Attempt to store an item and increment REAR using CAS if (Queue.compareAndSet((int) (rear % L) , x , newValue )) REAR.compareAndSet( rear , rear+1); Full - Help the other process if( getQueueValue(Queue.get((int)rear % L)) != 0) 9

10 10

11 Algorithm Behaviours Point contention
Number of simultaneously active processes Number of threads: 2 Number of total operations: 200 Thread1 Thread2 # op: 100 # op: 100 11

12 Algorithm Behaviours Point contention
Number of simultaneously active processes Number of threads: 4 Number of total operations: 200 Thread1 Thread2 Thread3 Thread4 # op: 50 # op: 50 # op: 50 # op: 50 12

13 Algorithm Behaviours Point contention
Number of simultaneously active processes Number of threads: 8 Number of total operations: 200 Thread1 Thread2 Thread3 Thread4 Thread5 Thread6 Thread7 Thread8 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 13

14 14

15 Questions? 15


Download ppt "IMPLEMENTATION OF A NON-BLOCKING QUEUE ALGORITHM"

Similar presentations


Ads by Google