• Prevent race condition
    • Initialize variables when package initialization phase, it will happen before main function. And don't modify those variables after initialization.
    • Avoid modifying variables by multiple goroutine => Every goroutine take care of different variable modification.
    • Dont communicate by sharing memory, share memory by communicating
    • Can pass variable address to pipeline to confine goroutine to modify variable
    • Confine variables to different stages
    • Allow many goroutines to access one variable, but only one access variable at a time



What to read next

Previous / Next
Previous: Go - Cancel Job by close channel Next: Go - mutual exclusion
More like this
Subscribe via RSS: Macro · Tech

Tags:

Updated: