gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:38:53 24 4
gpt4 key购买 nike

链接https://golang.org/pkg/sync/声明“不应复制包含此包中定义的类型的值。”

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

最佳答案

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

关于戈朗 : Values containing the types defined in this package should not be copied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41220596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com