Thread Safe Stack : Stack « Collections Data Structure « C# / C Sharp






Thread Safe Stack

        
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Adsophic.Common.Util.DataStructures
{
    public class ThreadSafeStack<T>
    {
        private Stack<T> _stack = new Stack<T>();
        private object _lock = new object();

        public void Push(T obj)
        {
            lock (_lock)
            {
                _stack.Push(obj);
            }
        }

        public T Pop()
        {
            lock (_lock)
            {
                return _stack.Pop();
            }
        }

        public bool IsEmpty { get { return _stack.Count == 0; } }
    }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.new Stack(new int[] { 1, 2, 3, 4, 5, 6 })
2.new Stack())
3.Implements the stack data type using an arrayImplements the stack data type using an array
4.Stack demo Stack demo
5.Stack to arrayStack to array
6.illustrates the use of a Stackillustrates the use of a Stack
7.A stack class for charactersA stack class for characters
8.Demonstrate the Stack classDemonstrate the Stack class
9.Stack(T) Class represents a variable size last-in-first-out (LIFO) collection of instances of the same arbitrary type.
10.Overflow Stack
11.A Stacked array is an integer array that contains a sequence of ascending integers.
12.FixedSizeStack provides an easy Stack implementation width a fixed size to prevent Stack Overflows in another sense.
13.Stack abstraction that also supports the IList interface