I have two go routines:
func f1 {
... some code
// critical section 1 (CS1)
... critical section code
// end criticla section 1
... more code
}
func f2 {
... some code
// critical section 2 (CS2)
... critical section code
// end criticla section 2
... more code
}
func main() {
go f1()
go f2()
}
What is proper way to ensure that the critical sections in these routines always execute alternately?
In other words, CS1 should be executed only after CS2 and vice versa: CS1, CS2, CS1, CS2, CS1, etc.