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
A common pitfall for people learning about concurrency is why expressions like x = x + 1 can give unexpected results when it happens on multiple threads, since they look like a single instruction.
On the Sync chapter, the implementation of Inc() method isn't concurrently safe, but the reason why can be confusing for someone with no background on assembly:
func (c*Counter) Inc() {
c.value++
}
Proposed Solution
Highlight that although c.value++ looks like a single instruction, the compiled instruction is actually similar to this:
tmp:=x+1// instruction Ax=tmp// instruction B
And then show how the counter can fail depending on the order the goroutines are executed.
The text was updated successfully, but these errors were encountered:
Problem
A common pitfall for people learning about concurrency is why expressions like
x = x + 1
can give unexpected results when it happens on multiple threads, since they look like a single instruction.On the
Sync
chapter, the implementation of Inc() method isn't concurrently safe, but the reason why can be confusing for someone with no background on assembly:Proposed Solution
Highlight that although
c.value++
looks like a single instruction, the compiled instruction is actually similar to this:And then show how the counter can fail depending on the order the goroutines are executed.
The text was updated successfully, but these errors were encountered: