Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: fix data race for composite literal creation
This change fixes two data races related to composite literal creation. The first one isn't controversial as it is just about initializing the variable that contains the values in the right place, i.e. within the n.exec, so that this variable is local to each potential goroutine, instead of being racily shared by all goroutines. The second one is more worrying, i.e. having to protect the node typ with a mutex, because a call to func (t *itype) refType actually modifies the itype itself, which means it is not concurrent safe. The change seems to work, and does not seem to introduce regression, but it is still a concern as it probably is a sign that more similar guarding has to be done in several other places.
- Loading branch information
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type foo struct { | ||
bar string | ||
} | ||
|
||
func main() { | ||
for i := 0; i < 2; i++ { | ||
go func() { | ||
a := foo{"hello"} | ||
println(a) | ||
}() | ||
} | ||
time.Sleep(time.Second) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type foo struct { | ||
bar string | ||
} | ||
|
||
func main() { | ||
for i := 0; i < 2; i++ { | ||
go func() { | ||
a := foo{bar: "hello"} | ||
println(a) | ||
}() | ||
} | ||
time.Sleep(time.Second) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters