2
并发例程我有三个并发程序就是这样,打印问题与围棋
func Routine1() {
Print (value a, value b, value c)
Print (value a, value b, value c)
Print (value a, value b, value c)
}
func Routine2() {
Print (value e, value f, value g)
Print (value e, value f, value g)
Print (value e, value f, value g)
}
func Routine3() {
Print (value x, value y, value z)
Print (value x, value y, value z)
Print (value x, value y, value z)
}
func main() {
go Routine1(command12, response12, command13, response13)
go Routine2(command12, response12, command23, response23)
Routine3(command13, response13, command23, response23)
}
现在我面对的问题是,有时它会发生,作为三个并行程序,有时打印结果语句没有正确执行意味着不打印整个,有一些东西插入另一个打印。例如,例程1的打印(值a,值b,值c)给出类似于值a,值b,值g的输出,其中值g由例程2插入。有人可以建议我,我该如何阻止它?我已经尝试过sync-mutex程序。然而,可能是因为我的代码太长,可能是我不能以正确的方式锁定解锁,所以它给出了一个死锁错误。任何人都可以建议我如何以简单的方式或以较低风险的同步互斥过程来实现这些目标。
有关我的这个问题的更多信息可以找到here。
谢谢。这是非常好的程序。让我尝试。 – Arpssss