- Learn Data Structures and Algorithms with Golang
- Bhagvan Kommadi
- 107字
- 2021-06-24 15:37:50
Synchronized queue
A synchronized queue consists of elements that need to be processed in a particular sequence. Passenger queue and ticket processing queues are types of synchronized queues, as follows:
//main package has examples shown
// in Hands-On Data Structures and algorithms with Go book
package main
// importing fmt package
import (
"fmt"
"time"
"math/rand"
)
// constants
const (
messagePassStart = iota
messageTicketStart
messagePassEnd
messageTicketEnd
)
//Queue class
type Queue struct {
waitPass int
waitTicket int
playPass bool
playTicket bool
queuePass chan int
queueTicket chan int
message chan int
}
We will discuss the different methods of synchronized queue in the following sections.