forked from steger/pr3-sose2026
deadlock
parent
ff4a4b2023
commit
c47b686210
|
|
@ -1,17 +1,43 @@
|
|||
package main
|
||||
|
||||
func print(ci <-chan int) {
|
||||
//TODO: implement
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func printChannel(ci <-chan int, done chan<- bool) {
|
||||
defer func() { done <- true }()
|
||||
for i := range ci {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fmt.Println(i)
|
||||
}
|
||||
}
|
||||
|
||||
func printWaitgroup(ci <-chan int, wg *sync.WaitGroup) {
|
||||
defer func() { wg.Done() }()
|
||||
for i := range ci {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fmt.Println(i)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
c := make(chan int)
|
||||
|
||||
//done := make(chan bool)
|
||||
//go printChannel(c, done)
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
go printWaitgroup(c, &wg)
|
||||
|
||||
c <- 1
|
||||
c <- 2
|
||||
c <- 3
|
||||
close(c)
|
||||
|
||||
print(c)
|
||||
//<-done
|
||||
wg.Wait()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue