Skip to content

Array stack is a bounded lock-based stack using an array. It uses a common lock for both push and pop operations.

License

Notifications You must be signed in to change notification settings

moocf/array-stack.java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Array stack is a bounded lock-based stack using an array. It uses a common lock for both push and pop operations.

Course: Concurrent Data Structures, Monsoon 2020
Taught by: Prof. Govindarajulu Regeti

push():
1. Lock stack.
2. Try push.
3. Unlock stack.
pop():
1. Lock stack.
2. Try pop.
3. Unlock stack.
tryPush():
1. Ensure stack is not full
2. Save data at top.
3. Increment top.
tryPop():
1. Ensure stack is not empty.
2. Decrement top.
3. Return data at top.
## OUTPUT
Starting 10 threads with sequential stack
7: failed pop
1: failed pop
5: failed pop
8: failed pop
9: failed pop
1: popped 0/1000 values
5: popped 158/1000 values
7: popped 0/1000 values
8: popped 0/1000 values
9: popped 31/1000 values
Was LIFO? false

Starting 10 threads with array stack
Was LIFO? true

See ArrayStack.java for code, Main.java for test, and repl.it for output.

references

Image Image

About

Array stack is a bounded lock-based stack using an array. It uses a common lock for both push and pop operations.

Topics

Resources

License

Stars

Watchers

Forks

Languages