liveBook · Manning

WriteLock

As explained in Learn Concurrent Programming with Go

WriteLock is a function that acquires the exclusive write side of the book's readers-writer mutex implementation.

WriteLock acquires the exclusive write side of a readers–writer mutex. It locks globalLock, so a writer blocks until every active reader has called ReadUnlock. section 4.2.2

The function contains one operation: rw.globalLock.Lock(). Readers share access, but the first reader locks globalLock and the last reader releases it, making writers wait during the entire read phase.

Acquiring the write side

func (rw *ReadWriteMutex) WriteLock() { rw.globalLock.Lock() } // exclusive update rw.WriteLock() // modify shared state rw.WriteUnlock()

How Learn Concurrent Programming with Go covers it

How deep it goes
Defines the single locking operation and relates it to reader counting, stopping short of broader fairness guarantees.
Examples
Uses a Go method that locks globalLock before an exclusive shared-state update.
What it assumes
Assumes goroutines, mutex locking, shared resources, and critical sections.
What you can do after
Operate a custom readers–writer mutex by acquiring and later releasing its exclusive write lock.
How it connects
Connects readers–writer mutexes, ReadLock, ReadUnlock, WriteUnlock, global locks, and critical sections.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.