Go Concurrency: Difference between revisions
Line 16: | Line 16: | ||
=Memory Access and Thread Synchronization Primitives= | =Memory Access and Thread Synchronization Primitives= | ||
The <code>[[Go Package sync#Overview|sync]]</code> package provides memory access and thread synchronization primitives. | |||
{{Internal|Go_Package_sync#Memory_Access_Synchronization_Primitives|Memory Access Synchronization Primitives}} | {{Internal|Go_Package_sync#Memory_Access_Synchronization_Primitives|Memory Access Synchronization Primitives}} | ||
{{Internal|Go_Package_sync#Thread_Synchronization_Primitives|Thread Synchronization Primitives}} | {{Internal|Go_Package_sync#Thread_Synchronization_Primitives|Thread Synchronization Primitives}} | ||
=Patterns= | =Patterns= |
Revision as of 00:03, 3 January 2024
Internal
Overview
The majority of languages address concurrency by providing a representation of O/S threads or green threads at language level, and exposing memory access synchronization primitives to protect data in presence of concurrent access.
Go takes a different approach. The fundamental concurrent execution primitive is the goroutine, exposed by the language with the language keyword go
. Goroutines are managed by the Go runtime, which maps them transparently over threads. While Go provides memory access and thread synchronization primitives at the language level via the sync
package, language guidelines do not exactly encourage their use, unless in very specific situations. Go provides an alternative concurrency programming model in language, based on Communicating Sequential Processes (CSP), a theoretical model introduced by A. Hoare in the "Communicating Sequential Processes" 1978 ACM paper. This concurrency programming model uses channels, which are exposed at language level with the chan
keyword.
Goroutines
Channels
Memory Access and Thread Synchronization Primitives
The sync
package provides memory access and thread synchronization primitives.