-
Notifications
You must be signed in to change notification settings - Fork 0
/
goroutines.go
30 lines (30 loc) · 1.02 KB
/
goroutines.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Concurrency X Parallelism
*
* - Concurrency: (Interruptability) => two lines of customers on the same cashier (lines taking turns ordering)
* - Parallelism: (Independentability) => two lines of customers ordering from two cashiers (each line has its own cashier)
*
*
* ====> See exercise_equivalent_binary_trees for an implementation of goroutines with channels <====
*
* To use goroutine, just add the "go" syntax before a method or function
* Example: go Fibonacci()
*
* => Channels are ways through which you can send and receive values from a routine.
* They can be created as:
* ch := make(chan int)
*
* ch <- v // Send v to channel ch.
* v := <-ch // Receive from ch, and assign value to v.
*
* (The data flows in the direction of the arrow.)
*
* v, ok := <-ch
* // ok is false if there are no more values to receive and the channel is closed.
*
* The loop
* for i := range ch
* receives values from the channel repeatedly until it is closed.
*
*
**/