cs_lang:go
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cs_lang:go [2012/04/30 09:23] – cedric | cs_lang:go [2014/04/18 23:19] (current) – [Books] cedric | ||
---|---|---|---|
Line 32: | Line 32: | ||
</ | </ | ||
+ | |||
+ | ===== Producer-consumer problem ===== | ||
+ | <code go> | ||
+ | package main | ||
+ | |||
+ | import (" | ||
+ | |||
+ | var done = make(chan bool) | ||
+ | var cake = make(chan int) | ||
+ | |||
+ | func produce (firstname string) { | ||
+ | for i := 0; i < 10; i++ { | ||
+ | fmt.Printf(" | ||
+ | cake <- i | ||
+ | } | ||
+ | done <- true | ||
+ | } | ||
+ | |||
+ | func consume (firstname string) { | ||
+ | for { | ||
+ | cake_number := <-cake | ||
+ | fmt.Printf(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | func main () { | ||
+ | go produce(" | ||
+ | go consume(" | ||
+ | go consume(" | ||
+ | <- done | ||
+ | } | ||
+ | </ | ||
===== Fork bomb ===== | ===== Fork bomb ===== | ||
Line 61: | Line 93: | ||
====== Books ====== | ====== Books ====== | ||
- | < | ||
- | <div id=" | ||
- | </ | ||
- | |||
[[https:// | [[https:// |
cs_lang/go.1335770589.txt.gz · Last modified: 2012/04/30 09:23 by cedric