I have three concurrent routines like this,
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)
}
Now what problem I am facing is, sometimes it will happen that, as the result of three concurrent routines, sometimes the print statement is not executing properly means not printing whole, there is some thing inserted by another print. For example, Print (value a, value b, value c) of routine 1 gives output like value a, value b, value g where value g is inserted by routine 2. Can anybody suggest me, how can I stop it ? I have tried sync-mutex procedure. However may be as my code is too long and may be I can not put lock-unlock in a right way, so it is giving a deadlock error. Can anybody suggest me how can I implement those in a simple way or in a less risky sync-mutex procedure.
More info about this problem of mine can be found here.