You have multiple goroutines reading from a single channel in Go. How would you ensure that each goroutine receives the data only once?
- Use a buffered channel
- Use a sync.Mutex
- Use a sync.Once
- Use a sync.WaitGroup
In this scenario, utilizing a sync.Mutex ensures that each goroutine receives the data only once by synchronizing access to a shared resource, preventing concurrent access.
Loading...
Related Quiz
- What is the performance complexity of the map operations in Go?
- You need to design a system to efficiently find whether a value is present in a collection of millions of items. Which data structure in Go would you use and why?
- Describe how you would implement a concurrent file processing system in Go.
- Anonymous functions in Go can access and modify variables from the _______ scope.
- You're designing a security module for your Go application. Which operator would you use to perform constant-time comparison of two byte slices to prevent timing attacks?