Atomic Stack Assignment

From CSE231 Wiki
Revision as of 21:27, 1 February 2023 by Cosgroved (talk | contribs)
Jump to navigation Jump to search

Motivation

We will build a thread-safe implementation of a Stack using atomics.

Background

Atomics

AtomicReference<V>

get()
compareAndSet(expect, update)

Code To Implement

AtomicStack

While ConcurrentStack could simply rely on synchronized to provide thread-safety, AtomicStack must change its data structure. To be @ThreadSafe, AtomicStack must correctly use AtomicReference<V>.

Do NOT hold any intrinsic locks (via synchronized). It would be wasteful (and missing the point) to pay the lock overhead when the AtomicReference will get the job done.

class: AtomicStack.java Java.png
methods: constructor
push
peek
pop
package: stack.atomic.exercise
source folder: student/src/main/java

constructor and instance variables

Be sure to initialize whatever state you need to implement a mutable thread-safe Stack using atomics.

push

peek

pop

Testing

class: __AtomicStackTestSuite.java Junit.png
package: stack.atomic.exercise
source folder: testing/src/test/java

Pledge, Acknowledgments, Citations

file: atomic-stack-pledge-acknowledgments-citations.txt

More info about the Honor Pledge