Guest User

Untitled

a guest
May 28th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. func main() {
  2.  
  3. // your queue of jobs
  4. q := make(chan int)
  5. // done channel takes the result of the job
  6. done := make(chan bool)
  7.  
  8. numberOfWorkers := 2
  9. for i := 0; i < numberOfWorkers; i++ {
  10. go worker(q, i, done)
  11. }
  12.  
  13. // appends a job to the queue
  14.  
  15. numberOfJobs := 17
  16. for j := 0; j < numberOfJobs; j++ {
  17. go func(j int) {
  18. q <- j
  19. }(j)
  20. }
  21.  
  22. for c := 0; c < numberOfJobs; c++ {
  23. <-done
  24. }
  25. }
Add Comment
Please, Sign In to add comment