From b7ef3c9a5465762a19cec6bc925ddeda1a6b441a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 27 Oct 2011 12:22:45 -0700 Subject: [PATCH] spec: define that initialization is sequential This is true of the existing implementations, and I think it is an important property to guarantee. R=golang-dev, r, borman, r CC=golang-dev https://golang.org/cl/5321058 --- doc/go_spec.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index fed7ed0348..34d8c81397 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -5149,12 +5149,22 @@ func main() { … }

Program execution begins by initializing the main package and then invoking the function main. -

-

When the function main returns, the program exits. It does not wait for other (non-main) goroutines to complete.

+

+Package initialization—variable initialization and the invocation of +init functions—happens in a single goroutine, +sequentially, one package at a time. +An init function may launch other goroutines, which can run +concurrently with the initialization code. However, initialization +always sequences +the init functions: it will not start the next +init until +the previous one has returned. +

+

Run-time panics