-
-
Save slingamn/886ebeba32f04294028cf0a60a8cc8c0 to your computer and use it in GitHub Desktop.
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 | |
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 {} | |
} |
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 | |
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