|
|
@ -2,8 +2,8 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"math"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func sum(a []int, c chan int) {
|
|
|
|
func sum(a []int, c chan int) {
|
|
|
@ -11,7 +11,7 @@ func sum(a []int, c chan int) {
|
|
|
|
for _, v := range a {
|
|
|
|
for _, v := range a {
|
|
|
|
sum += v
|
|
|
|
sum += v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
to_sleep := time.Duration(100 * math.Abs(float64(sum))) * time.Millisecond
|
|
|
|
to_sleep := time.Duration(100*math.Abs(float64(sum))) * time.Millisecond
|
|
|
|
fmt.Printf("Sleeping %s...\n", to_sleep)
|
|
|
|
fmt.Printf("Sleeping %s...\n", to_sleep)
|
|
|
|
time.Sleep(to_sleep)
|
|
|
|
time.Sleep(to_sleep)
|
|
|
|
c <- sum
|
|
|
|
c <- sum
|
|
|
@ -27,5 +27,5 @@ func main() {
|
|
|
|
fmt.Printf("x = %d\n", x)
|
|
|
|
fmt.Printf("x = %d\n", x)
|
|
|
|
y := <-c
|
|
|
|
y := <-c
|
|
|
|
fmt.Printf("y = %d\n", y)
|
|
|
|
fmt.Printf("y = %d\n", y)
|
|
|
|
fmt.Println(x, y, x + y)
|
|
|
|
fmt.Println(x, y, x+y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|