backup de julho
[h2N7SspZmY.git] / data / cache / a / a1697f87ed5d6eda5d2886a6350ae654.i
blob2652bfc2635f31b7fe1086f95cf198d21187d50a
1 a:24:{i:0;a:3:{i:0;s:14:"document_start";i:1;a:0:{}i:2;i:0;}i:1;a:3:{i:0;s:6:"p_open";i:1;a:0:{}i:2;i:0;}i:2;a:3:{i:0;s:7:"p_close";i:1;a:0:{}i:2;i:1;}i:3;a:3:{i:0;s:12:"section_edit";i:1;a:4:{i:0;i:-1;i:1;i:0;i:2;i:1;i:3;s:0:"";}i:2;i:1;}i:4;a:3:{i:0;s:6:"header";i:1;a:3:{i:0;s:2:"Go";i:1;i:1;i:2;i:1;}i:2;i:1;}i:5;a:3:{i:0;s:12:"section_open";i:1;a:1:{i:0;i:1;}i:2;i:1;}i:6;a:3:{i:0;s:6:"p_open";i:1;a:0:{}i:2;i:17;}i:7;a:3:{i:0;s:5:"cdata";i:1;a:1:{i:0;s:1:"
2 ";}i:2;i:18;}i:8;a:3:{i:0;s:12:"externallink";i:1;a:2:{i:0;s:18:"http://golang.org/";i:1;s:2:"Go";}i:2;i:19;}i:9;a:3:{i:0;s:5:"cdata";i:1;a:1:{i:0;s:2:": ";}i:2;i:44;}i:10;a:3:{i:0;s:13:"interwikilink";i:1;a:4:{i:0;s:28:"wp>Go_(programming_language)";i:1;s:2:"Go";i:2;s:2:"wp";i:3;s:25:"Go_(programming_language)";}i:2;i:46;}i:11;a:3:{i:0;s:7:"p_close";i:1;a:0:{}i:2;i:81;}i:12;a:2:{i:0;s:6:"plugin";i:1;a:4:{i:0;s:7:"uparrow";i:1;a:1:{i:0;s:42:"lib/plugins/uparrow/images/tango-small.png";}i:2;i:1;i:3;s:6:"~~UP~~";}}i:13;a:3:{i:0;s:13:"section_close";i:1;a:0:{}i:2;i:83;}i:14;a:3:{i:0;s:12:"section_edit";i:1;a:4:{i:0;i:1;i:1;i:82;i:2;i:1;i:3;s:2:"Go";}i:2;i:83;}i:15;a:3:{i:0;s:6:"header";i:1;a:3:{i:0;s:8:"Examples";i:1;i:2;i:2;i:83;}i:2;i:83;}i:16;a:3:{i:0;s:12:"section_open";i:1;a:1:{i:0;i:2;}i:2;i:83;}i:17;a:3:{i:0;s:4:"file";i:1;a:3:{i:0;s:71:"
3 PROG = prog_name
5 all: $(PROG)
7 %: %.8
8 8l -o $@ $<
10 %.8: %.go
11 8g $<
12 ";i:1;s:4:"make";i:2;s:8:"makefile";}i:2;i:110;}i:18;a:3:{i:0;s:4:"file";i:1;a:3:{i:0;s:286:"
13 /* hello */
15 package main // executável principal sempre deve pertencer a este pacote
17 import . "fmt" // importa funções de saída formatada (Printf)
19 // função principal (como em C)
20 func main() {
21 //sem o . no import teríamos que utilizar fmt.Printf
22 Printf("hello, world\n")
24 ";i:1;s:1:"c";i:2;s:8:"hello.go";}i:2;i:210;}i:19;a:3:{i:0;s:4:"file";i:1;a:3:{i:0;s:2013:"
25 /* pc_channel_multi.go */
27 package main
29 import (
30 . "fmt"
31 "crypto/rand"
32 "time"
33 "flag"
36 func random_between (begin, end int64) int64 {
37 random_byte := make([]byte, 1)
38 rand.Read(random_byte)
39 return int64(random_byte[0]) % (end - begin + 1) + begin
42 func random_sleep () {
43 time.Sleep(random_between(0, *MAX_SLEEP_TIME) * 10e7)
46 func send (channel chan int, i int) {
47 channel <- i
50 func recv (channel chan int) int {
51 return <-channel
54 func signal (channel chan int) {
55 if len(channel) < cap(channel) || cap(channel) == 0 {
56 channel <- 0
60 func wait (channel chan int) {
61 <-channel
64 var (
65 BUFFER_SIZE = flag.Int("s", 5, "BUFFER_SIZE") // flag -s
66 MAX_SLEEP_TIME = flag.Int64("t", 5, "MAX_SLEEP_TIME") // flag -t
67 MAX_PRODUCTIONS = flag.Int("m", 0, "MAX_PRODUCTIONS, 0 for infinity") // flag -m
68 N_PRODUCERS = flag.Int("p", 3, "N_PRODUCERS") // flag -p
69 N_CONSUMERS = flag.Int("c", 3, "N_CONSUMERS") // flag -c
70 pipe = make(chan int, *BUFFER_SIZE)
71 quit = make(chan int)
74 func producer (id int) {
75 for i := 0; i < *MAX_PRODUCTIONS || *MAX_PRODUCTIONS == 0; i++ {
76 Println(id, "producing:", i + id * 1e5)
77 send(pipe, i + id * 1e5)
78 random_sleep()
80 signal(quit)
83 func consumer (id int) {
84 for {
85 v := recv(pipe)
86 if closed(pipe) { // canal fechado?
87 break
89 Println("\t\t\t", id, "consuming:", v)
90 random_sleep()
92 signal(quit)
95 func main () {
96 flag.Parse() // processa flags
97 Println("BUFFER_SIZE =", *BUFFER_SIZE)
98 Println("MAX_SLEEP_TIME =", *MAX_SLEEP_TIME)
99 Println("MAX_PRODUCTIONS =", *MAX_PRODUCTIONS)
100 Println("N_PRODUCERS =", *N_PRODUCERS)
101 Println("N_CONSUMERS =", *N_CONSUMERS)
102 for i := 0; i < *N_PRODUCERS; i++ { // cria produtores
103 go producer(i + 1)
105 for i := 0; i < *N_CONSUMERS; i++ { // cria consumidores
106 go consumer(i + 1)
108 for i := 0; i < *N_PRODUCERS; i++ { // espera o término dos produtores
109 wait(quit)
111 close(pipe) // fecha comunicação
112 for i := 0; i < *N_CONSUMERS; i++ { // espera o término dos consumidores
113 wait(quit)
116 ";i:1;s:1:"c";i:2;s:20:"producer_consumer.go";}i:2;i:522;}i:20;a:2:{i:0;s:6:"plugin";i:1;a:4:{i:0;s:7:"uparrow";i:1;a:1:{i:0;s:42:"lib/plugins/uparrow/images/tango-small.png";}i:2;i:1;i:3;s:6:"~~UP~~";}}i:21;a:3:{i:0;s:13:"section_close";i:1;a:0:{}i:2;i:2566;}i:22;a:3:{i:0;s:12:"section_edit";i:1;a:4:{i:0;i:83;i:1;i:0;i:2;i:2;i:3;s:8:"Examples";}i:2;i:2566;}i:23;a:3:{i:0;s:12:"document_end";i:1;a:0:{}i:2;i:2566;}}