-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
31 lines (25 loc) · 884 Bytes
/
main.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
31
package main
import (
"fmt"
"time"
)
// main demonstrates the simple concept of a goroutine.
// It does not use any synchonisation mechanisms other
// than a very naive time.Sleep() call to cause a ctx switch
// and an arbitrary delay.
//
// Do not ever do this kind of approach.
func main() {
// saySomething will (at some non deterministic) point in the future be ran in
// a goroutine which are multiplexed on an arbitrary number of OS threads.
// The go runtime will not wait for this to complete before exiting.
go saySomething("foo")
time.Sleep(time.Second)
// A race condition exists here; this could exit before printing anything.
// Goroutines are considered daemon threads and waiting for them to finish
// is not something the go runtime will do.
}
// saySomething prints a simple phrase to stdout.
func saySomething(phrase string) {
fmt.Println(phrase)
}