You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code in the book works because the updater goroutine sleeps for 1 second before acquiring the lock. This ensures that the Listener goroutines have time to acquire the lock and check if the condition is met. However, if the sleep is removed or reduced to a very short duration (e.g., time.Nanosecond), the code may not work as expected.
I believe there might be two reasons for this:
The Updater goroutine competes with the Listener goroutines, preventing them from acquiring the lock.
The two Listener goroutines compete with each other. For example, the f(15) goroutine might consistently succeed in acquiring the lock. After f(15) releases the lock, the Updater goroutine might acquire it, which could prevent the f(10) goroutine from ever getting the lock.
The text was updated successfully, but these errors were encountered:
Describe the book error
The code in the book works because the updater goroutine sleeps for 1 second before acquiring the lock. This ensures that the Listener goroutines have time to acquire the lock and check if the condition is met. However, if the sleep is removed or reduced to a very short duration (e.g.,
time.Nanosecond
), the code may not work as expected.I believe there might be two reasons for this:
f(15)
goroutine might consistently succeed in acquiring the lock. Afterf(15)
releases the lock, the Updater goroutine might acquire it, which could prevent thef(10)
goroutine from ever getting the lock.The text was updated successfully, but these errors were encountered: