// Pop retrieves the topmost element from the stack.
// A LimitError is returned when the stack is empty.
Pop retrieves the topmost element from the stack.
A LimitError is returned when the stack is empty.
// Pop retrieves the topmost element from the stack . // A LimitError is returned when the stack is empty .
func (s *Stack) Pop() (interface{}, error) {
	spin := s.spin
	for {
		head := atomic.LoadUint32(s.head)
		unlockedHead := head & unlockMask
		lockedHead := head | lockMask
		if unlockedHead == 0 {
			return nil, LimitError{"Stack is empty"}
		}
		if atomic.CompareAndSwapUint32(s.head, unlockedHead, lockedHead) {
			data := s.data[unlockedHead-1]             
			atomic.StoreUint32(s.head, unlockedHead-1) 
			return data, nil                           
		}
		spin.Yield()
	}
}
func ( s * Stack ) Pop ( ) ( interface { } , error ) { spin := s . spin for { head := atomic . LoadUint32 ( s . head ) unlockedHead := head & unlockMask lockedHead := head | lockMask if unlockedHead == 0 { return nil , LimitError { " " } } if atomic . CompareAndSwapUint32 ( s . head , unlockedHead , lockedHead ) { data := s . data [ unlockedHead - 1 ] atomic . StoreUint32 ( s . head , unlockedHead - 1 ) return data , nil } spin . Yield ( ) } }
Pop retrieves the topmost element from the stack.
Pop retrieves the topmost element from the stack .
// Always work with unlocked head as head might be locked // copy data // unlock // ### return ###