Skip to content

Instantly share code, notes, and snippets.

@slingamn
Last active March 20, 2018 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slingamn/886ebeba32f04294028cf0a60a8cc8c0 to your computer and use it in GitHub Desktop.
Save slingamn/886ebeba32f04294028cf0a60a8cc8c0 to your computer and use it in GitHub Desktop.
package main
var target bool
func writer() {
for {
target = false
target = true
}
}
func reader() {
for {
local := target
if !(local == false || local == true) {
panic("this condition is nonsensical")
}
}
}
func main() {
go writer()
go reader()
select {}
}
package main
var target int
const (
LOW = 0
HIGH = (1 << 31) - 1
)
func writer() {
for {
target = LOW
target = HIGH
}
}
func reader() {
for {
local := target
if !(local == LOW || local == HIGH) {
panic("interleave observed")
}
}
}
func main() {
target = LOW
go writer()
go reader()
select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment