The ConcurrentStack<T>
data structure is a concurrent version of a standard Stack<T>
collection. It contains three main methods: Push
, TryPop,
and TryPeek
, to append, retrieve and get the item from the collection by FILO (First In, Last Out) principle.
ConcurrentStack<T>
is implemented as a singly-linked lock-free list, which makes it less interesting in terms of reviewing the implementation details. Nevertheless, it is still useful to know, and if we have to choose a concurrent data structure for a scenario where elements processing order is not important, it is preferable to use a concurrent queue since it has less performance overhead. Appending elements to the concurrent stack always leads to additional memory allocation, which can be a significant drawback in certain scenarios.