]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: clarify the safety of Template.New
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 16 Apr 2019 13:13:47 +0000 (22:13 +0900)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 7 Jun 2019 13:56:20 +0000 (13:56 +0000)
In particular, the returned template isn't independent from the parent.
For example, it can't be parsed concurrently with other children
templates. Only methods which are explicitly safe for concurrent use,
like Execute, may be used concurrently.

Fixes #30281.

Change-Id: Idc84bf4199c035316cdb83b950fd4a8f2a71cd0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/172297
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/text/template/template.go

index 41cdd5682c165c8ee2099dcdfdef7e65bc836112..1135d819b99ae91d492b127e4e81159822e6481a 100644 (file)
@@ -50,6 +50,10 @@ func (t *Template) Name() string {
 // New allocates a new, undefined template associated with the given one and with the same
 // delimiters. The association, which is transitive, allows one template to
 // invoke another with a {{template}} action.
+//
+// Because associated templates share underlying data, template construction
+// cannot be done safely in parallel. Once the templates are constructed, they
+// can be executed in parallel.
 func (t *Template) New(name string) *Template {
        t.init()
        nt := &Template{