Golang
Why choose GO:
- typed and compiled
- small / fast to learn
- last enough community to having staying power and packages implemented
From CS343
- Non-object-oriented, light-weight (like μC++) non-preemptive threads (called goroutine).
- cooperative scheduling: implicitly inserts yields at safe points (not interrupt based).
- busy waiting only on multicore (Why?)
- go statement (like start/fork) creates a new user thread running in routine.
go foo(3, f) // start thread in routine foo
- Arguments may be passed to goroutine but return value is discarded
- Cannot reference goroutine object no direct communication
- Threads synchronized/communicate via channel (CSP)
- paradigm shift from routine call!!!
- Channel is typed shared buffer with 0 to N elements.
- Buffer size > 0 ⇒ up to N asynchronous calls; otherwise, synchronous call.
- Operator ← performs send/receive.
- send:
ch1 <- 1
- receive:
s <- ch2
- send:
- Channel can be constrained to only send or receive; otherwise bi-directional.
- More like futures and
_Select
, and asynchronous call.