<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] >[success] ## **goroutine入門案例** 請編寫一個程序,完成如下功能: 1)在主線程(可以理解成進程)中,開啟一個goroutine,該協程每隔1秒輸出"hello,world" 2)在主線程中也每隔一秒輸出"hello,golang",輸出10次后,退出程序 3)要求主線程和goroutine同時執行 <br> ![](https://img.kancloud.cn/0e/2d/0e2d7babc59cf94388387c450fb39a87_1209x633.png) <br> **運行結果** ![](https://img.kancloud.cn/65/e4/65e45b78adaad4ab0d62d82c0e7005e0_1209x611.png) <br> 4)畫出主線程和協程執行流程圖 ![](https://img.kancloud.cn/21/36/21364dcce783cf36d5b8e7c63e1bc7f4_865x720.png) <br> <br> ### **入門案例小結:** 1)主線程是一個物理線程(**主線程是由操作系統控制的**),直接作用在cpu上的。是重量級的,非常耗費cpu資源。 2)協程從主線程開啟的,是輕量級的線程,是邏輯態。對資源消耗相對小。 3)**Golang的協程機制是重要的特點,可以輕松的開啟上萬個協程**其它編程語言的并發機制是一般基于線程的,開啟過多的線程,資源耗費大,這里就突顯Golang在并發上的優勢了
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看