implement a lock-free stack.

implement a lock-free stack..  Your stack needs to support two opera

tions,

PUSH

and

POP

. Your

25

stack must be capable of reusing nodes/data (re-

PUSH

-ing after

POP

-ing), and it should not be possible to

lose data or otherwise corrupt the stack.

Next, implement an elimination stack based on an elimination array, as described in

the textbook. It

should resort to your lock-free stack implementation if an exchange fails. T

he size of the elimination

array and the timeout used to wait for an elimination partner should be paramete

rs.

Stacks are tested by starting

p

threads that then repeatedly perform

PUSH

or

POP

operations on the stack,

randomly choosing one operation or the other with equal probability. A threa

d should retain the last 10

items it popped, and when performing a

PUSH

, 50% of the time it should randomly select a previously

popped node to re-push (if it has any). After each push/pop operation

, a thread sleeps for a random time

between 0ms and

d

ms. Each thread should also keep track of how many pushes it does and ho

w many

pops successfully returned actual data

implement a lock-free stack.

Posted in Uncategorized

Leave a Reply