Created
September 29, 2017 12:43
-
-
Save tsonglew/b7c22c2508d234a41dc9bfd0bfc57cec to your computer and use it in GitHub Desktop.
A leaky buffer
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 freeList = make(chan *Buffer, 100) | |
var serverChan = make(chan *Buffer) | |
func client() { | |
for { | |
var b *Buffer | |
select { | |
case b = <-freeList: | |
default: | |
b = new(Buffer) | |
} | |
load(b) | |
serverChan <- b | |
} | |
} | |
func server() { | |
for { | |
b := <-serverChan | |
process(b) | |
select { | |
case freeList <- b: | |
default: | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment