Commit ae05f00b authored by Rob Pike's avatar Rob Pike

update tutorial for new export scheme

R=ken,rsc
DELTA=101  (9 added, 0 deleted, 92 changed)
OCL=23174
CL=23188
parent 35e37bbf
This diff is collapsed.
......@@ -46,7 +46,7 @@ func (r13 *rotate13) Read(b []byte) (ret int, err *os.Error) {
func (r13 *rotate13) String() string {
return r13.source.String()
}
// end of Rotate13 implementation
// end of rotate13 implementation
func cat(r reader) {
const NBUF = 512;
......
......@@ -4,35 +4,35 @@
package main
type Request struct {
type request struct {
a, b int;
replyc chan int;
}
type BinOp (a, b int) int;
type binOp (a, b int) int;
func Run(op *BinOp, request *Request) {
func run(op *BinOp, request *Request) {
result := op(request.a, request.b);
request.replyc <- result;
}
func Server(op *BinOp, service chan *Request) {
func server(op *BinOp, service chan *Request) {
for {
request := <-service;
go Run(op, request); // don't wait for it
go run(op, request); // don't wait for it
}
}
func StartServer(op *BinOp) chan *Request {
func startServer(op *BinOp) chan *Request {
req := make(chan *Request);
go Server(op, req);
return req;
}
func main() {
adder := StartServer(func(a, b int) int { return a + b });
adder := startServer(func(a, b int) int { return a + b });
const N = 100;
var reqs [N]Request;
var reqs [N]request;
for i := 0; i < N; i++ {
req := &reqs[i];
req.a = i;
......
......@@ -22,10 +22,10 @@ func filter(in, out chan int, prime int) {
}
}
// The prime sieve: Daisy-chain Filter processes together.
// The prime sieve: Daisy-chain filter processes together.
func main() {
ch := make(chan int); // Create a new channel.
go generate(ch); // Start Generate() as a goroutine.
go generate(ch); // Start generate() as a goroutine.
for {
prime := <-ch;
print(prime, "\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment