You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Enqueue put element into queuefunc (q*CircularQueue[T]) Enqueue(valueT) error {
ifq.IsFull() {
returnerrors.New("queue is full!")
}
q.data[q.rear] =valueq.rear= (q.rear+1) %q.capacityreturnnil
}
// Dequeue remove head element of queue and return it, if queue is empty, return nil and errorfunc (q*CircularQueue[T]) Dequeue() (*T, error) {
ifq.IsEmpty() {
returnnil, errors.New("queue is empty")
}
headItem:=q.data[q.front]
vartTq.data[q.front] =tq.front= (q.front+1) %q.capacityreturn&headItem, nil
}
上面两个方法没有加锁,会不会存在并发安全问题?
是不是只能自己在外部调用的时候加锁呢?
The text was updated successfully, but these errors were encountered:
上面两个方法没有加锁,会不会存在并发安全问题?
是不是只能自己在外部调用的时候加锁呢?
The text was updated successfully, but these errors were encountered: