课程: Hands-On Introduction: Go

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Challenge 8: Goroutine synchronization

Challenge 8: Goroutine synchronization - Go教程

课程: Hands-On Introduction: Go

Challenge 8: Goroutine synchronization

- [Instructor] This challenge will reinforce our understanding of goroutine synchronization by expanding on a previous challenge. We'll use a modified version of our solution to the interface challenge and introduce goroutines to have the counters do their work in separate threads. If we open up the main .go file, the starter file for this challenge, we can see that everything is pretty much very familiar here. We still have the counters, interface, the letter counter implementations for the number, the symbols, the letter. Not much has changed here, other than at the top of the file, we have a package global random which is a type rand.Rand. And we have an init function to that, make sure we initialize this random with a source that is changing to ensure that we have non-deterministic numbers whenever we need to generate a new random number. And inside of the counter methods themselves, we have this artificial…

内容