Last active
December 9, 2016 08:21
-
-
Save heppu/adf35c4906cc6c4530fadbf5f3e35784 to your computer and use it in GitHub Desktop.
Revisions
-
heppu revised this gist
Dec 9, 2016 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ func main() { var wg sync.WaitGroup workers := make(chan struct{}, Limit) doWork := func(i int, j string) { defer wg.Done() time.Sleep(2 * time.Second) @@ -23,13 +23,11 @@ func main() { for j := 0; j < 15; j++ { work := string(rune(97 + j)) log.Printf("Work %s enqueued\n", work) workers <- struct{}{} wg.Add(1) go doWork(j, work) } wg.Wait() } -
heppu revised this gist
May 23, 2016 . 1 changed file with 4 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,28 +11,25 @@ const Limit = 5 func main() { log.SetFlags(log.Ltime) // format log output hh:mm:ss var wg sync.WaitGroup workers := make(chan struct{}, Limit) doWork := func(i int, j string) { defer wg.Done() time.Sleep(2 * time.Second) log.Printf("Worker %d working on %s\n", i, j) <-workers } for j := 0; j < 15; j++ { work := string(rune(97 + j)) log.Printf("Work %s enqueued\n", work) workers <- struct{}{} wg.Add(1) go doWork(j, work) } wg.Wait() } -
heppu revised this gist
May 23, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ func main() { log.SetFlags(log.Ltime) // format log output hh:mm:ss wg := sync.WaitGroup{} queue := make(chan struct{}, Limit) doWork := func(i int, j string) { defer wg.Done() @@ -27,7 +27,7 @@ func main() { log.Printf("Work %s enqueued\n", work) wg.Add(1) queue <- struct{}{} go doWork(j, work) } -
heppu revised this gist
May 23, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ func main() { log.SetFlags(log.Ltime) // format log output hh:mm:ss wg := sync.WaitGroup{} queue := make(chan bool, Limit) doWork := func(i int, j string) { defer wg.Done() @@ -27,12 +27,12 @@ func main() { log.Printf("Work %s enqueued\n", work) wg.Add(1) queue <- false go doWork(j, work) } close(queue) wg.Wait() } -
heppu revised this gist
May 23, 2016 . No changes.There are no files selected for viewing
-
heppu created this gist
May 23, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ package main import ( "log" "sync" "time" ) const Limit = 5 func main() { log.SetFlags(log.Ltime) // format log output hh:mm:ss wg := sync.WaitGroup{} queue := make(chan interface{}, Limit) doWork := func(i int, j string) { defer wg.Done() time.Sleep(2 * time.Second) log.Printf("Worker %d working on %s\n", i, j) <-queue } for j := 0; j < 15; j++ { work := string(rune(97 + j)) log.Printf("Work %s enqueued\n", work) wg.Add(1) queue <- nil go doWork(j, work) } close(queue) wg.Wait() }