3 // Copyright 2015 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
17 // Allocate more Ps than processors. This raises
18 // the chance that we get interrupted by the OS
19 // in exactly the right (wrong!) place.
21 runtime.GOMAXPROCS(2 * p)
23 // Allocate some pointers.
24 ptrs := make([]*int, p)
25 for i := 0; i < p; i++ {
29 // Arena where we read and write pointers like crazy.
30 collider := make([]*int, p)
32 done := make(chan struct{}, 2*p)
34 // Start writers. They alternately write a pointer
35 // and nil to a slot in the collider.
36 for i := 0; i < p; i++ {
39 for j := 0; j < N; j++ {
40 // Write a pointer using memmove.
41 copy(collider[i:i+1], ptrs[i:i+1])
42 // Write nil using memclr.
43 // (This is a magic loop that gets lowered to memclr.)
44 r := collider[i : i+1]
52 // Start readers. They read pointers from slots
53 // and make sure they are valid.
54 for i := 0; i < p; i++ {
57 for j := 0; j < N; j++ {
59 copy(ptr[:], collider[i:i+1])
60 if ptr[0] != nil && ptr[0] != ptrs[i] {
61 panic(fmt.Sprintf("bad pointer read %p!", ptr[0]))
67 for i := 0; i < 2*p; i++ {