Assignment 4 - that uses the AtomicInteger class to provide...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Assignment 4 Due Date: April 10, 2012 In this assignment, you will use Java's atomic variable classes (AtomicXXX in java.util.concurrent.atomic) that provide efficient CAS operations on numeric and reference types to build non-blocking, lock-free data structures. Part 1 Below is a thread-safe implementation of a pseudo-random number generator: public class ReentrantLockPseudoRandom extends PseudoRandom { private final Lock lock = new ReentrantLock(false); private int seed; ReentrantLockPseudoRandom (int seed) { this.seed = seed; } public int nextInt (int n) { lock.lock(); try { int s = seed; seed = calculateNext(s); int remainder = s % n; return remainder > 0 ? remainder : remainder + n; } finally { lock.unlock(); } } } Write a test driver that repeatedly invokes an instance of the generator. The test driver should perform some number of busy-work iterations (that should be customizable); the computation performed by these iterations should operate only on thread-local data. Part 2 Provide an implementation of a non-blocking pseudo-random number generator
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: that uses the AtomicInteger class to provide lock-free access to the seed. Part 3 Modify the test driver so that it invokes each of these implementations in turn. Measure the performance of the two implementations by varying the number of threads that invoke the generator from within the driver. How does performance vary as contention increases? Contention is inversely correlated to the percentage of time spent performing thread-local computation. Part 4 Following our general description of implementing a lock-free queue, implement a non-blocking lock-free concurrent stack algorithm using the AtomicReference class to represent the top element in the stack. You need to provide operations to concurrently push and pop elements off the stack; since this is a lock-free algorithm, your solution should not involve the use of locks or synchronization (other than compareAndSet) ....
View Full Document

This note was uploaded on 03/26/2012 for the course CS 390 taught by Professor Staff during the Spring '08 term at Purdue University.

Page1 / 2

Assignment 4 - that uses the AtomicInteger class to provide...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online