Skip to content

Commit

Permalink
fix(queue): overflow with exit status 1 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrktia authored Jul 20, 2024
1 parent f1aec4d commit bb6f761
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion datastructure/queue.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package datastructure

import "sync"
import (
"fmt"
"os"
"sync"
)

type queue struct {
list []any
Expand All @@ -19,6 +23,11 @@ func new(size int) *queue {
func (q *queue) add(k any) {
q.lock.Lock()
defer q.lock.Unlock()
// check if queue is full before adding
if q.lastAdded == len(q.list) {
fmt.Printf("queue is full\n")
os.Exit(1)
}
q.list[q.lastAdded] = k
q.lastAdded++
}
Expand Down

0 comments on commit bb6f761

Please sign in to comment.