Created
March 5, 2021 05:02
-
-
Save SealinGp/1cead9410e026337a9924e01490bb27c to your computer and use it in GitHub Desktop.
CSP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"time" | |
) | |
type cond struct { | |
ch1 chan struct{} | |
ch2 chan struct{} | |
ch3 chan struct{} | |
sema1 int32 | |
sema2 int32 | |
} | |
func (c *cond) printA() { | |
for { | |
<-c.ch1 | |
log.Println("A") | |
c.ch2 <- struct{}{} | |
} | |
} | |
func (c *cond) printB() { | |
for { | |
<-c.ch2 | |
log.Println("B") | |
c.ch3 <- struct{}{} | |
} | |
} | |
func (c *cond) printC() { | |
for { | |
<-c.ch3 | |
log.Println("C") | |
log.Println("--------------------------------") | |
c.ch1 <- struct{}{} | |
} | |
} | |
func main() { | |
var con = new(cond) | |
con.ch1 = make(chan struct{}) | |
con.ch2 = make(chan struct{}) | |
con.ch3 = make(chan struct{}) | |
go con.printC() | |
go con.printB() | |
go con.printA() | |
con.ch1 <- struct{}{} | |
time.Sleep(1 * time.Second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment