Metered concurrency: Difference between revisions
Content deleted Content added
Go solution |
→{{header|Go}}: updated to use new WaitGroup feature |
||
Line 335:
"fmt"
"time"
"sync"
)
Line 346 ⟶ 347:
go librarian(acquire, release, count, 10)
nStudents := 20
var studied sync.WaitGroup
studied
// wait until all students are done▼
for i := 0; i < nStudents; i++ {
}
studied.Wait()
}
Line 367 ⟶ 365:
p = nil
}
case <-r: // release/v operation
count++
p = a
Line 376 ⟶ 374:
}
func student(a, r
a <- 0 // accquire
fmt.Println("Studying...") // report per task descrption
time.Sleep(2e9) // sleep per task description
r <- 0 // release
}</lang>
Output shows 10 students studying immediately, about a 2 second pause, 10 more students studying, then another pause of about 2 seconds before returning to the command prompt.
|