duanbei1598
2013-12-14 13:47
浏览 50
已采纳

为什么该程序在我的系统上终止而不在操场上终止?

Consider this program:

package main

import "fmt"
import "time"
import "runtime"

func main() {

    x := 0

    go func() {
        time.Sleep(500 * time.Millisecond)
        x = 1
    }()

    for x == 0 {
        runtime.Gosched()
    }

    fmt.Println("it works!")
}

Why does it terminate locally but not on Playground? Does the termination of my program rely on undefined behavior?

图片转代码服务由CSDN问答提供 功能建议

请考虑以下程序:

  package main 
 
import  “ fmt” 
import“ time” 
import“ runtime” 
 
func main(){
 
x:= 0 
 
 go func(){
 time.Sleep(500 * time.Millisecond)\  nx = 1 
}()
 
 x == 0 {
 runtime.Gosched()
} 
 
 fmt.Println(“ it works!”)
} 
   
 
 

为什么它在本地终止,而不在游乐场终止 ? 程序的终止是否依赖未定义的行为?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题