In Go versions prior to 1.5, a piece of code involving runtime.Gosched() was observed to affect the output of a program:
func say(s string) { for i := 0; i输出,runtime.gosched():
在1.5之前的GO版本中说明hello world hello world hello world hello world helloGOMAXPROCS and Cooperative Multitasking
hello hello hello hello hello设置为大于1的值,Goroutines可以并行运行。但是,与先发制人的多任务系统不同,Goroutines仍然必须明确产生控制,以允许其他Goroutines执行。这是因为Go使用合作的多任务处理,在该方法中,Goroutines自愿投降到调度程序。对并行性[&& && && && &&华度的启示都设置为大于1的值,这可以使goroutines的互动范围内的互动式互动,因为他们可以在他们之间进行不确定的时间进行执行。这可能会导致不可预测的输出模式,如上面的示例,当GomaxProcs设置为2时。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3