-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
96 lines (70 loc) · 4.08 KB
/
notes.txt
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
NOTES ON GO -- THE LANGUAGE
website and references:
http://golang.org
http://blog.golang.org/
http://software.intel.com/en-us/blogs/2010/01/21/parallel-programming-talk-60-russ-cox-about-the-google-go-programming-language/
-Created by Rob Pike, Ken Thompson (and Russ Cox)
- Imperative, statically typed language
- Semicolons after braces
- Scala like declaration -- type follows variable name
- Supports UTF-8 natively
- 6g compiler for 64 bit, 8-g compiler for 32 bit. History from Plan 9.
- Initializing declaration with :=
- gccgo -- requires you to build the entire gcc with go enabled.
- for is the only looping construct
- runtime parallelism is not enabled by default in 6g. need to enable it
explicitly by setting environment variable GOMAXPROCS or import
runtime package and call runtime.GOMAXPROCS(NCPU).
- the go keyword can call anonymous functions. See prime sieve example
- Receivers always block until there is data to receive. If the
channel is unbuffered, the sender blocks until the receiver has
received the value. If the channel has a buffer, the sender blocks
only until the value has been copied to the buffer; if the buffer is
full, this means waiting until some receiver has retrieved a value.
- Go does have shared memory support. Including mutexes, etc. But it's
explicitly discouraged. These are provided in the "sync" package.
- sync.WaitGroup: A WaitGroup waits for a collection of goroutines to finish.
- sync.Once.Do: Do calls the function f if and only if the method is
being called for the first time with this receiver.
- Condition variables
- Channels are multi reader multi writer queues. If there are multiple
receivers on a single channel, then the messages sent will be
received by one of them. There is no way to broadcase messages from
a sender to many receivers built in within the language.
- Message based system. It's a cross between a message passing actor
based system and something like pthreads.
- Borrows from CSP, Occam and Erlang.
- Garbage collection required for concurrency?
- Channels of functions are possible!! https://groups.google.com/group/golang-nuts/browse_thread/thread/407202933c87a2e2/6e977766cf2cd867?lnk=gst&q=waitgroup#6e977766cf2cd867
- Why does using GOMAXPROCS > 1 sometimes make my program slower?
(This is specific to the gc compilers. See above.)
It depends on the nature of your program. Programs that contain
several goroutines that spend a lot of time communicating on channels
will experience performance degradation when using multiple OS
threads. This is because of the significant context-switching penalty
involved in sending data between threads.
Go's goroutine scheduler is not as good as it needs to be. In future,
it should recognize such cases and optimize its use of OS threads. For
now, GOMAXPROCS should be set on a per-application basis.
- Goroutines are multiplexed on OS threads.
- gccgo now supported with gcc 4.6. Not enabled by default. Use
--enable-languages while configuring
Go. http://gcc.gnu.org/gcc-4.6/changes.html
- Go supported on gdb
- Non blocking communications operations gone -- select statement can
do them more cleanly from http://www.youtube.com/watch?v=-i0hat7pdpk
- Find out what is "defer" Go's defer statement schedules a function
call (the deferred function) to be run immediately before the
function executing the defer returns. It's an unusual but effective
way to deal with situations such as resources that must be released
regardless of which path a function takes to return. The canonical
examples are unlocking a mutex or closing a file.
- Find out what happens with "_"
- Select has semantics derived from Newsqueak http://plan9.bell-labs.com/who/rsc/thread/newsqueak.pdf
- RSC notes that https://groups.google.com/group/golang-nuts/browse_thread/thread/d12cdd9a6cb6da99/83c6c8fcb8595139?lnk=raot
This is a popular split but hardly the only definition
of those terms. One reason we use the name goroutine
is to avoid preconceptions about what those terms mean.
For many people threads also connotes management by
the operating system, while goroutines are managed first
by the Go runtime.