aboutsummaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/atomic/value.go14
-rw-r--r--src/sync/cond.go12
-rw-r--r--src/sync/mutex.go2
-rw-r--r--src/sync/pool.go3
-rw-r--r--src/sync/rwmutex.go2
-rw-r--r--src/sync/waitgroup.go4
6 files changed, 37 insertions, 0 deletions
diff --git a/src/sync/atomic/value.go b/src/sync/atomic/value.go
index ab3aa11285..30abf72634 100644
--- a/src/sync/atomic/value.go
+++ b/src/sync/atomic/value.go
@@ -12,7 +12,11 @@ import (
// Values can be created as part of other data structures.
// The zero value for a Value returns nil from Load.
// Once Store has been called, a Value must not be copied.
+//
+// A Value must not be copied after first use.
type Value struct {
+ noCopy noCopy
+
v interface{}
}
@@ -83,3 +87,13 @@ func (v *Value) Store(x interface{}) {
// Disable/enable preemption, implemented in runtime.
func runtime_procPin()
func runtime_procUnpin()
+
+// noCopy may be embedded into structs which must not be copied
+// after the first use.
+//
+// See https://github.com/golang/go/issues/8005#issuecomment-190753527
+// for details.
+type noCopy struct{}
+
+// Lock is a no-op used by -copylocks checker from `go vet`.
+func (*noCopy) Lock() {}
diff --git a/src/sync/cond.go b/src/sync/cond.go
index f711c39da2..c070d9d84e 100644
--- a/src/sync/cond.go
+++ b/src/sync/cond.go
@@ -20,6 +20,8 @@ import (
// A Cond can be created as part of other structures.
// A Cond must not be copied after first use.
type Cond struct {
+ noCopy noCopy
+
// L is held while observing or changing the condition
L Locker
@@ -84,3 +86,13 @@ func (c *copyChecker) check() {
panic("sync.Cond is copied")
}
}
+
+// noCopy may be embedded into structs which must not be copied
+// after the first use.
+//
+// See https://github.com/golang/go/issues/8005#issuecomment-190753527
+// for details.
+type noCopy struct{}
+
+// Lock is a no-op used by -copylocks checker from `go vet`.
+func (*noCopy) Lock() {}
diff --git a/src/sync/mutex.go b/src/sync/mutex.go
index 78b115cf5a..90892793f0 100644
--- a/src/sync/mutex.go
+++ b/src/sync/mutex.go
@@ -19,6 +19,8 @@ import (
// A Mutex is a mutual exclusion lock.
// Mutexes can be created as part of other structures;
// the zero value for a Mutex is an unlocked mutex.
+//
+// A Mutex must not be copied after first use.
type Mutex struct {
state int32
sema uint32
diff --git a/src/sync/pool.go b/src/sync/pool.go
index 2acf505f3c..bf29d88c5c 100644
--- a/src/sync/pool.go
+++ b/src/sync/pool.go
@@ -40,7 +40,10 @@ import (
// that scenario. It is more efficient to have such objects implement their own
// free list.
//
+// A Pool must not be copied after first use.
type Pool struct {
+ noCopy noCopy
+
local unsafe.Pointer // local fixed-size per-P pool, actual type is [P]poolLocal
localSize uintptr // size of the local array
diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go
index 9fc6e3bd2c..455d412330 100644
--- a/src/sync/rwmutex.go
+++ b/src/sync/rwmutex.go
@@ -16,6 +16,8 @@ import (
// RWMutexes can be created as part of other
// structures; the zero value for a RWMutex is
// an unlocked mutex.
+//
+// An RWMutex must not be copied after first use.
type RWMutex struct {
w Mutex // held if there are pending writers
writerSem uint32 // semaphore for writers to wait for completing readers
diff --git a/src/sync/waitgroup.go b/src/sync/waitgroup.go
index 029e6077cd..b386e1fec2 100644
--- a/src/sync/waitgroup.go
+++ b/src/sync/waitgroup.go
@@ -15,7 +15,11 @@ import (
// goroutines to wait for. Then each of the goroutines
// runs and calls Done when finished. At the same time,
// Wait can be used to block until all goroutines have finished.
+//
+// A WaitGroup must not be copied after first use.
type WaitGroup struct {
+ noCopy noCopy
+
// 64-bit value: high 32 bits are counter, low 32 bits are waiter count.
// 64-bit atomic operations require 64-bit alignment, but 32-bit
// compilers do not ensure it. So we allocate 12 bytes and then use