Golang:不应复制包含此包中定义的类型的值

Golang: Values containing the types defined in this package should not be copied

linkhttps://golang.org/pkg/sync/状态"Values containing the types defined in this package should not be copied."

为什么会这样?如果我忽略建议会怎样?

它不再作为同步原语工作。充其量你会得到不可预测的行为。 将锁(例如)想象成一个标志。如果它被锁定,则标志被设置。如果你复制那个锁(你复制标志的状态),副本会表现得好像它被锁定了,而实际上它没有。如果您解锁副本,原件不会改变,因此它会表现得好像它已被锁定,而实际上它不应再被锁定。