**func (p *linkedList) showalldoctorsrecursive() error {
defer wg.Done()
mutex.Lock()
{
if p.head != nil {
printRecursiveF(p.head)
} else {
fmt.Println("The list is empty.")
}
}
mutex.Unlock()
return nil
}
func (p *linkedList) showalldoctorsfront() error {
defer wg.Done()
mutex.Lock()
{
if p.head != nil {
printfront(p.head)
} else {
fmt.Println("The list is empty.")
}
}
mutex.Unlock()
return nil
}
func printRecursiveF(n *Node2) {
if n != nil {
printRecursiveF(n.next)
fmt.Println(n.item, n.next.time)
}
}
func printfront(n *Node2) {
if n != nil {
fmt.Println(n.item)
fmt.Println(n.item, n.next.time)
}
}**
func (p *queue) displayallpatients() error {
defer wg.Done()
mutex.Lock()
{
currentNode := p.front
if currentNode == nil {
fmt.Println("There are no patients.")
return nil
}
fmt.Println("Displaying all patients and their appointment times")
fmt.Println(currentNode.item, currentNode.time)
for currentNode.next != nil {
currentNode = currentNode.next
fmt.Println(currentNode.item, currentNode.time)
}
}
mutex.Unlock()
return nil
}
func main() {
var num, num1, num2 int
runtime.GOMAXPROCS(2)
wg.Add(3)
myList := &linkedList{nil, 0}
myQueue := &queue{nil, nil, 0}
for {
fmt.Println("Please enter 1 to check for patient or 2 to check for doctor.Alternatively,enter 3 to exit menu")
fmt.Scanln(&num)
_, err := mainmenu(num)
if err != nil {
fmt.Println(err)
} else if num == 3 {
break
} else {
fmt.Printf("Please proceed to the main menu >")
}
我尝试运行 goroutines 并应用互斥锁和延迟。但是,在运行goroutines时,我将面临恐慌。有没有办法解决这个问题?我创建了一个队列和链表,其中包含一些要显示的函数,enqueue(add)和dequeue(pop),并为此应用了一些并发性。我知道这一点,n是你运行的goroutine的数量,你想使用互斥锁来确保goroutines一次运行一个。wg.Add(n)
牧羊人nacy
至尊宝的传说
相关分类