In a concurrent program, you need to share data between multiple goroutines. How would you ensure safe access to shared data using pointers in Go?

  • Use atomic operations
  • Use channels
  • Use mutexes
  • Use pointers with read-write locks
Using mutexes is a common way to ensure safe access to shared data in Go. Mutexes provide exclusive access to the shared resource, allowing only one goroutine to access it at a time. By locking and unlocking the mutex appropriately, you can prevent race conditions and ensure data integrity.
Add your answer
Loading...

Leave a comment

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