1 / 15

Chien-Hua Shann, Ting-Lu Huang and Cheng Chen National Chiao Tung University

Chien-Hua Shann, Ting-Lu Huang and Cheng Chen National Chiao Tung University. IMPLEMENTATION OF A NON-BLOCKING QUEUE ALGORITHM. Nastaran Shafiei. 1. Outline. Algorithm Description Class Diagram Algorithm Implementation Results. 2. Finite array, Q Counters, FRONT and REAR

borna
Download Presentation

Chien-Hua Shann, Ting-Lu Huang and Cheng Chen National Chiao Tung University

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Outline • Algorithm Description • Class Diagram • Algorithm Implementation • Results 2

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

  4. NonblockingQueue L: int 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 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. 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 Implementation of Enqueue.run() 8

  9. 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) REAR.compareAndSet( rear , rear+1); Implementation of Enqueue.run() 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 Thread5 Thread6 Thread7 Thread8 Thread1 Thread2 Thread3 Thread4 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 # op: 25 13

  14. 14

  15. Questions? 15

More Related