Skip to content

Commit f1ddb4d

Browse files
committed
add
1 parent 7356e55 commit f1ddb4d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

happens_before/four.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
//as above, but with the send and receive statements swapped and using an unbuffered channel
4+
5+
//var cc = make(chan int)
6+
7+
//If the channel were buffered (e.g., c = make(chan int, 1))
8+
// then the program would not be guaranteed to print "hello, world".
9+
var cc = make(chan int, 1)
10+
var aaaa string
11+
12+
func fff() {
13+
aaaa = "hello, world"
14+
<-cc
15+
}
16+
17+
//is also guaranteed to print "hello, world".
18+
func main() {
19+
go fff()
20+
cc <- 0
21+
print(aaaa)
22+
}

0 commit comments

Comments
 (0)