V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
yangbuwei
V2EX  ›  Go 编程语言

go 中让出时间片和顺序执行的区别?

  •  
  •   yangbuwei · 2018-10-15 10:31:51 +08:00 · 2661 次点击
    这是一个创建于 1991 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如题,既然如此那我让时间片存在的的意义何在呢?直接顺序执行不就好了?我能想到唯一的好处就是主协程等待其他协程用完,本人刚刚开始自学 go,想到什么问什么,要是比较弱智希望不要喷我。
    7 条回复    2018-10-16 10:13:42 +08:00
    reus
        1
    reus  
       2018-10-15 11:44:29 +08:00
    不知道你在想什么,建议学习操作系统课程,多进程多线程部分,思而不学则殆啊
    yangbuwei
        2
    yangbuwei  
    OP
       2018-10-15 14:47:35 +08:00
    @reus 我的意思是他具体应用在哪些场景
    mengzhuo
        3
    mengzhuo  
       2018-10-15 15:27:22 +08:00
    同 1L 看不懂,应用层程序是不知道时间片存在的。

    我猜你是指:runtime.Gosched()
    https://golang.org/pkg/runtime/#Gosched
    文档说得很清楚了。
    Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, so execution resumes automatically.
    tourist2018
        4
    tourist2018  
       2018-10-15 15:53:01 +08:00
    @yangbuwei #2 runtime.Gosched() 单纯这个方法在项目里面用的确实不多 但这是语言特性 你非得和应用结合什么鬼
    yangbuwei
        5
    yangbuwei  
    OP
       2018-10-16 10:08:04 +08:00
    @tourist2018 我都说了,我刚刚看到那一块,,所以问一下,你回答就回答,秀优越是什么鬼?什么鬼?
    yangbuwei
        6
    yangbuwei  
    OP
       2018-10-16 10:09:10 +08:00
    @mengzhuo 我其实说的不是应用层,,而是说在实际使用的时候,它用在什么场景,,不过你已经说明白了,感谢
    tourist2018
        7
    tourist2018  
       2018-10-16 10:13:42 +08:00
    @tourist2018 #4 你觉得是秀优越 好吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   951 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:35 · PVG 05:35 · LAX 14:35 · JFK 17:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.