Re:Clang vs. Clang
by saagarjha on Monday August 05, 2024 @06:47AM
(#41159907)
This is just UB.
[ Parent
| on HN ]
Re:Clang vs. Clang
by tsimionescu on Monday August 05, 2024 @07:19AM
(#41160126)
Yes, this is an example of UB leaving memory in a bad state.
If you want an example of something that is not UB leaving memory in a bad state, here is some Go code:
global := 7;
func main () {
go func() {
global = 1000000;
}()
go func() {
global = 10
}()
fmt.Printf("gloabl is now %d")
}
The two concurrent writes may partially overlap, and global may have a value that is neither 7 nor 10 nor 1000000. The program's memory is in a bad state, but none of this is UB in the C or C++ sense. In particular, the Go compiler is not free to compile this program into something entirely different.Edit: I should also note that a similar C program using pthreads or win32 threading for concurrent access is also an example of a program which will go into a bad state, but that is not UB per the C standard (since the C standard has no notion of multithreading).
The C standard definitely has opinions on races
Re:Clang vs. Clang
by tsimionescu on Saturday August 10, 2024 @07:12AM
(#41208700)
Please share a link.