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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *