Go course

MutexesQuiz: Mutexes

Go

Display

Theme

Mutexes · Quiz

Quiz: Mutexes

Test what you know about race conditions, sync.Mutex, sync.RWMutex, and sync.Once. Answer every question in the panel on the right.

  1. Question 1 of 5Why can jumlah++ run from many goroutines produce a smaller number than it should?
  2. Question 2 of 5What's the main problem with this method?
    type Skor struct {
    	mu    sync.Mutex
    	nilai int
    }
    
    func (s Skor) Tambah() {
    	s.mu.Lock()
    	defer s.mu.Unlock()
    	s.nilai++
    }
  3. Question 3 of 5With sync.RWMutex, which of these is ALLOWED to happen at the same time?
  4. Question 4 of 5What happens if 100 goroutines call once.Do(inisialisasi) on the same sync.Once?
  5. Question 5 of 5You need to count the total number of requests a web server receives across many handler goroutines. Which tool is the simplest and most appropriate?