Go Package sync: Difference between revisions
Line 19: | Line 19: | ||
==<tt>RWMutex</tt>== | ==<tt>RWMutex</tt>== | ||
{{Internal|Go Mutex and RWMutex#RWMutex|<tt>RWMutex</tt>}} | {{Internal|Go Mutex and RWMutex#RWMutex|<tt>RWMutex</tt>}} | ||
==<tt>Pool</tt>== | |||
{{Internal|Go Pool|<tt>Pool</tt>}} | |||
=<span id='Thread_Synchronization_Primitives'></span>Execution Synchronization Primitives= | =<span id='Thread_Synchronization_Primitives'></span>Execution Synchronization Primitives= | ||
==<tt>WaitGroup</tt>== | ==<tt>WaitGroup</tt>== |
Revision as of 03:50, 20 January 2024
External
Internal
Overview
The sync
package provides memory access and execution synchronization primitives to use when synchronization between goroutines is necessary. However, other than the Once
and WaitGroup
types, most sync
primitives are intended for use by low-level library routines. Higher level synchronization is better done via channels and communication. Regarding Mutexes, the sync
package implements them, but the language designers expressed their hope that Go programming style will encourage people to try higher-level techniques. In particular, programmers should structure their program so that only one goroutine at a time is ever responsible for a particular piece of data.
Do not communicate by sharing memory. Instead, share memory by communicating.
Also see: