Suppose you're designing a system where multiple goroutines need to communicate with each other asynchronously. Which concurrency construct in Go would you use and why?
- Use a sync.Mutex to achieve mutual exclusion
- Use atomic operations for shared memory access
- Use channels due to their simplicity, safety, and built-in synchronization
- Use semaphores for resource synchronization
Channels are a preferred choice for inter-goroutine communication in Go due to their safety features and built-in synchronization, simplifying the development process.
Loading...
Related Quiz
- Explain the difference between short declaration := and the var keyword in Go.
- Which package in Go is commonly used to create an HTTP server?
- Database migration scripts are often version-controlled using _______.
- In Go, can type assertion be used with non-interface types?
- The method receiver in Go is specified in the _____ of the method.