chap1
Parallelism = simultaneous execution(doing things at once.)
Concurrency = the composition of independently executing processes.(dealing things at once.)
Do not communicate by sharing memory; instead, share memory by communicating.
other language = when concurrent threads need to share data, a lock is applied to the memory.
race conditions, memory management etc.
Go = send variable from one thread to another.
The receiver will wait till the value reaches.
The “waiting” -> synchronisation between threads when data is being exchanged.
An analogy
Concurrent: Mouse, keyboard, display, and disk drivers.
Parallel: Vector dot product.
https://talks.golang.org/2012/waza.slide#1
Goroutines
go
before a function call -> goroutine
Channel
a connection between two goroutines
unbufferedchannel := make(chan string)
bufferedchannel := make(chan int, 20)
unbuffered channel = no capacity = require both goroutines to be ready to make any exchange
When there is a sender-goroutine, but no receiver-goroutine, the channel will lock the sender and make it wait, vice versa.
One can not happen without the other.
Synchronization is inherent.
buffered channel = with capacity
If the buffer is full or empty, a buffered channel will behave very much like an unbuffered channel.
A sender will be locked if the buffered channel is full.
A receiver will be locked if the buffered channel is empty.
Last updated
Was this helpful?