{"id":180118,"date":"2020-10-29T11:07:35","date_gmt":"2020-10-29T03:07:35","guid":{"rendered":"http:\/\/4563.org\/?p=180118"},"modified":"2020-10-29T11:07:35","modified_gmt":"2020-10-29T03:07:35","slug":"c-%e6%9c%89%e6%b2%a1%e6%9c%89%e8%83%bd%e5%a4%9f%e5%af%b9%e6%a0%87-golang-%e7%9a%84-goroutine-%e7%9a%84%e5%8d%8f%e7%a8%8b%e5%ba%93%e5%95%8a%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=180118","title":{"rendered":"c++ \u6709\u6ca1\u6709\u80fd\u591f\u5bf9\u6807 golang \u7684 goroutine \u7684\u534f\u7a0b\u5e93\u554a\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  c++ \u6709\u6ca1\u6709\u80fd\u591f\u5bf9\u6807 golang \u7684 goroutine \u7684\u534f\u7a0b\u5e93\u554a\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6ee1\u8db3 stackful\uff0c\u80fd\u591f\u81ea\u52a8 yield \u7684\uff0c\u6709\u6ca1\u6709\uff1f \u770b\u4e86\u597d\u51e0\u4e2a\u90fd\u9700\u8981\u624b\u52a8 yield \u5f52\u8fd8 cpu\uff0c\u611f\u89c9\u6709\u70b9\u9ebb\u70e6\uff0c\u5e0c\u671b\u5927\u4f6c\u6307\u70b9\u4e0b\uff0c\u4e0d\u5962\u6c42\u540c\u65f6\u6709 channel \u548c select \u4e86<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>43<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3941479\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : keygen88 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u534f\u7a0b\u5e93\u5f88\u591a\uff0c\u4f46\u5f88\u591a\u5176\u5b83\u5e93\u4e0d\u652f\u6301\u5c31\u6bd4\u8f83\u9e21\u808b\u4e86\uff0c\u8fd9\u5c31\u662f\u4e2a\u751f\u6001\u95ee\u9898\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941480\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             goroutine \u672c\u6765\u5c31\u4e0d\u662f\u534f\u7a0b\uff0c\u5bf9\u6807\u7684\u5c31\u662f\u7ebf\u7a0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941481\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u52a8 yield \u5927\u6982\u8981\u80fd\u63d2\u5165\u4ee3\u7801\u5427\uff1f C++ \u5927\u6982\u6ca1\u6709\u8fd9\u79cd\u80fd\u529b\u3002<br \/>\u800c\u4e14 C++20 \u7684 stackless coroutine \u51fa\u6765\u4e4b\u540e\uff0cstackful \u7684\u53ef\u80fd\u4f1a\u8d8a\u6765\u8d8a\u5c11\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941482\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abbycin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             libgo \u770b\u8fc7\u6ca1\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941483\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @abbycin \u8c22\u8c22\uff0c\u6b63\u5728\u770b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941484\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 \u4e3a\u4ec0\u4e48 stackless \u66f4\u591a\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941485\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yc1992 \u56e0\u4e3a\u4eba\u4eec\u4f1a\u66f4\u503e\u5411\u4e8e\u4f7f\u7528\u8bed\u8a00\u672c\u8eab\u7684\u529f\u80fd\u5427\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941486\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @reus \u7b2c\u4e00\u6b21\u542c\u5230\u8fd9\u6837\u7684\u63cf\u8ff0                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941487\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nightwitch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/en.cppreference.com\/w\/cpp\/language\/coroutines<br \/>\u4e00\u5927\u6ce2\u5e93\u6b63\u5728\u8def\u4e0a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941488\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zunceng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65e9\u51e0\u5e74\u7528 asio coro \u73a9\u8fc7 <br \/>\u4e0d\u8fc7\u90a3\u4e2a\u4e0a\u9762\u7684 yield \u5c31\u662f\u5bf9 for loop &#8230; switch case \u505a\u4e86\u4e2a\u5c01\u88c5 \u7528\u8d77\u6765\u8fd8\u662f\u592a\u8d39\u8111                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941489\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @nightwitch \u8865\u5145\u4e00\u4e0b\uff0c\u5fc5\u987b c++11 \u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941490\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nannanziyu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yc1992<br \/>\u9650\u5b9a c++11 \u7684\u8bdd\uff0c\u5fae\u8f6f\u7684 cpprestsdk \u91cc\u6709\u4e00\u4e2a pplx                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941491\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : catror <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 asio+fiber \u5199\u8fc7\u4e00\u4e2a\u7f51\u7edc\u7a0b\u5e8f\u6846\u67b6\uff0c\u7528\u7740\u4e5f\u8fd8\u884c\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941492\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CRVV <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yc1992 <br \/>\u5982\u679c\u4f60\u53bb\u770b Go \u7684\u5b98\u65b9\u6587\u6863\uff0c\u91cc\u9762\u660e\u786e\u8bf4\u4e86\u8fd9\u4e1c\u897f\u4e0d\u662f coroutine\uff0c\u5f53\u7136\u5b83\u4e5f\u4e0d\u662f thread\uff0c\u6240\u4ee5\u624d\u8d77\u4e86\u4e2a\u65b0\u540d\u5b57\u53eb goroutine<\/p>\n<p>\u5927\u5bb6\u5e38\u8bf4\u5b83\u662f\u534f\u7a0b\uff0c\u662f\u56e0\u4e3a\u5b83\u548c\u534f\u7a0b\u5f88\u50cf\uff0c\u5728 io \u4e0a\u4e5f\u7528 epoll, kqueue, iocp \u8fd9\u4e9b\u7cfb\u7edf\u8c03\u7528\uff0c\u5e76\u4e14\u5b83\u4e5f\u786e\u5b9e\u5728 io \u64cd\u4f5c\u4e0a yield \u4e86\uff0c\u8001\u7248\u672c\u4e0a\u7684\u8c03\u5ea6\u5668\u8fd8\u4e0d\u662f\u62a2\u5360\u5f0f\u7684\u3002<\/p>\n<p>\u4f46\u9996\u5148\u65b0\u7684\u8c03\u8bd5\u5668\u5df2\u7ecf\u662f\u62a2\u5360\u5f0f\u7684\u4e86\uff0c\u8fd9\u5c31\u4e0d\u7b26\u5408\u534f\u7a0b\u7684\u5b9a\u4e49\u3002\u7136\u540e\u4f60\u5bf9\u6bd4\u4e00\u4e0b\u5b9e\u73b0\u7684\u7ec6\u8282\uff0c\u663e\u7136\u73b0\u5728\u7684 goroutine \u548c thread \u66f4\u63a5\u8fd1\u3002<\/p>\n<p>\u522b\u4eba\u600e\u4e48\u8bf4\u5e76\u4e0d\u91cd\u8981\uff0c\u4f60\u5f97\u53bb\u770b\u5b9e\u9645\u7684\u4e1c\u897f\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941493\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @CRVV \u4e0d\u540c\u7684\u8c03\u5ea6\u65b9\u5f0f\u800c\u5df2\uff0chttps:\/\/golang.org\/doc\/faq#goroutines \u91cc\u9762\u660e\u786e\u63d0\u5230\u4e86 coroutine                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941494\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yc1992 \u534f\u7a0b\u5f53\u7136\u662f\u534f\u4f5c\u5f0f\u8c03\u5ea6\uff0c\u4f46 goroutine \u5e76\u4e0d\u9650\u5236\u8c03\u5ea6\u65b9\u5f0f\uff0c\u73b0\u5728\u7684\u5b9e\u73b0\u5c31\u662f\u6709\u62a2\u5360\u5f0f\u7684\u8c03\u5ea6\u65b9\u5f0f\uff0c\u8dd1\u7740\u6b7b\u5faa\u73af\u7684 goroutine \u4e5f\u53ef\u4ee5\u88ab\u62a2\u5360\uff0c\u6240\u4ee5 goroutine \u5e76\u4e0d\u662f\u534f\u7a0b\u3002<br \/>FAQ \u90a3\u6bb5\u8bdd\u662f 11 \u5e74\u524d\u5199\u7684\uff1a https:\/\/github.com\/golang\/go\/commit\/d4a4468204448843d0dd15d2d4b89c29607a4a7e<br \/>\u90a3\u65f6\u5019\u7684 goroutine \u786e\u5b9e\u662f\u534f\u4f5c\u5f0f\u8c03\u5ea6\uff0c\u6ca1\u6709\u4efb\u4f55\u62a2\u5360\u673a\u5236\u3002\u4f46\u73b0\u5728 goroutine \u5df2\u7ecf\u4e0d\u662f 11 \u5e74\u524d\u90a3\u6837\u4e86\uff0cFAQ \u90a3\u6bb5\u8bdd\u662f\u8fc7\u65f6\u7684\u4e86\u3002\u4e0d\u4f1a\u6709\u4efb\u4f55\u534f\u7a0b\u5b9e\u73b0\u53ef\u4ee5\u6709 goroutine \u8fd9\u6837\u7684\u6027\u8d28\uff0c\u5c31\u7b97\u53ef\u4ee5\u81ea\u52a8\u8c03\u5ea6\uff0c\u4e5f\u505a\u4e0d\u5230\u62a2\u5360\u5f0f\u8c03\u5ea6\u3002\u53ea\u6709\u7ebf\u7a0b\u5177\u6709\u62a2\u5360\u5f0f\u8c03\u5ea6\u7684\u7279\u6027\uff0c\u6240\u4ee5\u8bf4 goroutine \u5bf9\u6807\u7ebf\u7a0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941495\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzbkl <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5 boost fiber                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941496\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zzzbkl \u770b\u4e86\u534a\u5929\uff0c\u4e0d\u4f1a\u7528\uff0c\u8c8c\u4f3c\u8981\u624b\u52a8 yield                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941497\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hdbzsgm <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             folly                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941498\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wnpllrzodiac <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             st?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941499\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @reus #16 \u4f60\u786e\u5b9a\uff1f go13 \u7684\u65f6\u5019\u5199\u4e2a\u6b7b\u5faa\u73af\u7167\u6837\u5361\u6b7b\u5176\u4ed6 goroutine \u554a\uff0c\u5565\u65f6\u5019\u6539\u4e86\u62a2\u5360\u5f0f\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941500\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : caviar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 go1.14 \u7684\u65f6\u5019\u5f00\u59cb\u7684 https:\/\/golang.org\/doc\/go1.14#runtime                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941501\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : user8341 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @caviar \u8fd9\u4e2a\u5f88\u65b0\uff0c\u53ef\u80fd\u5f88\u591a\u4eba\u8fd8\u6ca1\u7528\u4e0a<\/p>\n<p>Go 1.14 \u53d1\u5e03\u65e5\u671f\u662f\uff1a25 February 2020                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941502\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : BadMan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u5728\u4f7f\u7528\u5fae\u4fe1\u7684 libco\uff0c\u633a\u597d\u7528\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941503\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hronro <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c45\u7136\u8fd9\u4e48\u591a\u4eba\u8bf4 Go \u7684 goroutine \u4e0d\u662f\u534f\u7a0b\uff0c\u8fd8\u6709\u8bf4\u53ef\u4ee5\u62a2\u5360\u7684\u5c31\u4e0d\u662f\u534f\u7a0b\u3002<br \/>\u96be\u9053\u4e0d\u662f stackful coroutine \u90fd\u53ef\u4ee5\u505a\u5230\u62a2\u5360\u5417\uff1f stackless coroutine \u786e\u5b9e\u505a\u4e0d\u4e86\u62a2\u5360\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941504\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : framlog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             seastar                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941505\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : beidounanxizi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @reus \u8c03\u5ea6\u65b9\u5f0f\u6700\u65b0\u7248\u672c\u786e\u5b9e\u53d8\u4e86 \u5c24\u5176\u662f 1.10 \u4e4b\u540e \uff0c\u4f46\u662f GMP \u8fd9\u4e00\u6574\u5957\u903b\u8f91 \u662f\u4e0d\u662f\u8fd8\u662f\u8bf4\u548c\u5176\u4ed6 coroutine \u7684\u5dee\u4e0d\u591a\u5462\uff1f \u7591\u95ee\u8138.jpg                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941506\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sujin190 1.14                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941507\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @beidounanxizi \u548c\u54ea\u4e2a\u534f\u7a0b\u5b9e\u73b0\u5dee\u4e0d\u591a\uff1f\u8bf7\u4e3e\u51fa\u4f8b\u5b50\uff0c\u4e0d\u8981\u76f8\u5f53\u7136\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941508\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hankai17 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             swapcontext                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941509\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\u5c31\u666e\u9002\u6027\u800c\u8a00\uff0c\u548c goroutine \u5bf9\u7b49\u7684\uff0c\u4e5f\u662f\u7ebf\u7a0b\u3002\u5728 go \u91cc\uff0c\u4f60\u53ea\u80fd\u7528 goroutine\uff0c\u4e0d\u5b58\u5728\u5176\u4ed6\u5e76\u53d1\u5355\u5143\u3002\u800c C\/C++<br \/>\u91cc\uff0c\u80fd\u62c5\u5f53\u8fd9\u4e2a\u4efb\u52a1\u7684\uff0c\u53ea\u80fd\u662f pthread \u8fd9\u7c7b\u7ebf\u7a0b\u5e93\uff0c\u800c\u4e0d\u662f\u5176\u4ed6\u534f\u7a0b\u5e93\uff0c\u56e0\u4e3a\u534f\u7a0b\u5e93\u8fd8\u6ca1\u6709\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u4f60\u7528\u8fd9\u4e2a\uff0c\u4ed6\u7528\u90a3\u4e2a\uff0c\u6ca1\u6cd5\u878d\u5408\u7684\u3002<br \/>\u53e6\u5916\uff0c\u867d\u7136\u73b0\u5728\u4e3b\u6d41 pthread \u5b9e\u73b0\uff0c\u90fd\u662f 1:1 \u6620\u5c04\u5230\u7cfb\u7edf\u7ebf\u7a0b\uff0c\u4f46\u662f\uff0cM:N \u6620\u5c04\u5230\u7cfb\u7edf\u7ebf\u7a0b\u7684 pthread \u5b9e\u73b0\uff0c\u4e5f\u662f\u5b58\u5728\u7684\u3002pthread \u7ebf\u7a0b\uff0c\u548c goroutine\uff0c\u90fd\u53ea\u662f\u5e76\u53d1\u7684\u5355\u5143\uff0c\u5177\u4f53\u600e\u4e48\u5b9e\u73b0\uff0c\u5bf9\u4e8e\u4f7f\u7528\u8005\u662f\u4e0d\u53ef\u89c1\u7684\u3002goroutine \u5386\u53f2\u4e0a\u66fe\u7ecf\u5b9e\u73b0\u4e3a\u7eaf\u534f\u4f5c\u5f0f\u8c03\u5ea6\uff0c\u4e0d\u4ee3\u8868\u5b83\u5c31\u662f\u534f\u7a0b\u3002\u56e0\u4e3a\u5b83\u52a0\u5165\u62a2\u5360\u5f0f\u8c03\u5ea6\u4e4b\u540e\uff0c\u7a0b\u5e8f\u4e5f\u4e0d\u9700\u8981\u53d8\u5316\uff0c\u600e\u4e48\u8c03\u5ea6\u90fd\u4e0d\u5f71\u54cd\u8bed\u4e49\uff0c\u8fd9\u662f\u534f\u7a0b\u4e0d\u5177\u5907\u7684\u6027\u8d28\u3002\u534f\u7a0b\u8bed\u4e49\u4e00\u822c\u90fd\u4f1a\u6709\u786e\u5b9a\u7684\u8c03\u5ea6\u70b9\uff0c\u4f8b\u5982 yield \u8bed\u53e5\u3001await \u8bed\u53e5\uff0c\u800c\u4e0d\u4f1a\u662f\u4efb\u4f55\u5730\u65b9\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941510\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Balthild <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @reus \u4ece\u666e\u904d\u610f\u4e49\u4e0a\u8bb2\uff0c\u300c\u62a2\u5360\u5373\u975e\u534f\u7a0b\u300d\u4f3c\u4e4e\u4e0d\u90a3\u4e48\u7edd\u5bf9\u3002\u6bd4\u5982\uff0cRust \u6709\u62a2\u5360\u5f0f\u7684\u5f02\u6b65\u8fd0\u884c\u65f6\u5b9e\u73b0\uff0c\u6bd4\u5982 tokio \u3001smol \u7b49\u3002\u82e5\u6309\u300c\u62a2\u5360\u5373\u975e\u534f\u7a0b\u300d\u5b9a\u5f8b\uff0cRust \u7684\u5f02\u6b65\u5c31\u4e0d\u662f\u534f\u7a0b\u4e86\u3002\u4f46 Rust \u5f02\u6b65\u7684\u8bbe\u8ba1\u660e\u786e\u81ea\u5df1\u662f stackless coroutine \u3002\u8fd9\u9700\u8981\u5982\u4f55\u89e3\u91ca\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941511\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : missdeer <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8d5e\u540c 31 \u3002<\/p>\n<p>\u65e9\u4e9b\u5e74\uff0ccoroutine \u6982\u5ff5\u8fd8\u51e0\u4e4e\u4e0d\u89c1\u4e8e\u65e5\u5e38\u5f00\u53d1\uff0c\u5f88\u591a\u64cd\u4f5c\u7cfb\u7edf\uff08\u6bd4\u5982 DOS\uff0c\u4e00\u4e9b UNIX \uff09\u8fd8\u4e0d\u652f\u6301\u5185\u6838\u7ebf\u7a0b\u65f6\uff0c\u6709\u7b2c\u4e09\u65b9\u5e93\uff08\u6bd4\u5982 pthread)\u5b9e\u73b0\u7528\u6237\u6001\u7ebf\u7a0b\u53ca\u8c03\u5ea6\uff0c\u5f53\u7136\u540e\u6765 pthread \u7684\u5b9e\u73b0\u4e5f\u5343\u53d8\u4e07\u5316\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941512\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fpure <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @CRVV \u7eff\u8272\u7ebf\u7a0b\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941513\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Balthild tokio \u5e76\u4e0d\u662f\u62a2\u5360\u5f0f\u7684\u8fd0\u884c\u65f6\uff0ctokio \u6587\u6863\u91cc\u6e05\u6670\u8bf4\u4e86\u7684\uff1a https:\/\/tokio.rs\/blog\/2020-04-preemption <br \/>\u4f60\u5bf9\u201c\u62a2\u5360\u201d\u7684\u7406\u89e3\u6709\u8bef\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941514\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : reus <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Balthild \u5212\u51fa tokio \u6587\u6863\u91cc\u7684\u91cd\u70b9\u7ed9\u4f60\uff1a<br \/>A common solution to this problem is preemption. With normal OS threads, the kernel will interrupt execution every so often in order to ensure fair scheduling of all threads. <br \/>os \u7ebf\u7a0b\u652f\u6301\u62a2\u5360<br \/>Runtimes that have full control over execution (Go, Erlang, etc.) will also use preemption to ensure fair scheduling of tasks. <br \/>go \u3001erlang \u4e5f\u652f\u6301\u62a2\u5360<br \/>This is accomplished by injecting yield points \u2014 code which checks if the task has been executing for long enough and yields back to the scheduler if so \u2014 at compile-time. <br \/>\u63d2\u5165\u8c03\u5ea6\u70b9\uff0c\u8fd9\u662f go \u8fc7\u53bb\u7684\u505a\u6cd5\uff0c\u73b0\u5728\u589e\u52a0\u4e86\u7528\u4fe1\u53f7\u53bb\u62a2\u5360\u7684\u65b9\u5f0f<br \/>Unfortunately, Tokio is not able to use this technique as Rust&#8217;s async generators do not provide any mechanism for executors (like Tokio) to inject such yield points.<br \/>tokio \u4e0d\u652f\u6301\u62a2\u5360<\/p>\n<p>\u4f60\u7684\u5927\u524d\u63d0\u9519\u4e86\uff0c\u63a8\u8bba\u81ea\u7136\u5168\u9519\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941515\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CRVV <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Balthild <br \/>@hronro <\/p>\n<p>https:\/\/en.wikipedia.org\/wiki\/Coroutine#Comparison_with_threads<br \/>\u534f\u7a0b\uff0ccoroutine\uff0cco \u662f cooperatively\uff0c\u5408\u4f5c\u534f\u4f5c\u7684\u610f\u601d\u3002<br \/>\u76f8\u5bf9\u7684\u6982\u5ff5\u662f preemptively\uff0c\u62a2\u5360<\/p>\n<p>\u8fd9\u662f\u8fd9\u4e2a coroutine \u539f\u672c\u7684\u610f\u601d\u3002<\/p>\n<p>\u5728\u4e00\u4e2a stackful coroutine \u7684\u5b9e\u73b0\u4e0a\u52a0\u4e0a\u62a2\u5360\u5f0f\u8c03\u5ea6\uff0c\u90a3\u5f53\u7136\u53ef\u4ee5\u505a\u3002<br \/>\u4f46\u505a\u51fa\u6765\u7684\u4e1c\u897f\u5c31\u4e0d\u53eb coroutine \u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941516\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CRVV <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yc1992 <br \/>\u6211\u672c\u6765\u60f3\u8bf4\u7684\u5c31\u662f\u8fd9\u4e00\u6bb5\u3002<\/p>\n<p>When a coroutine blocks, such as by calling a blocking system call, the run-time automatically moves other coroutines on the same operating system thread to a different, runnable thread so they won&#8217;t be blocked.<\/p>\n<p>\u8fd9\u91cc\u8bf4\u7684\u4e0d\u662f\u628a\u591a\u4e2a coroutine \u653e\u5230\u540c\u4e00\u4e2a\u7ebf\u7a0b\u4e0a\u6765\u8dd1\u3002\u662f\u8bf4\u5982\u679c\u6709\u4e00\u4e2a coroutine \u963b\u585e\u4f4f\u4e86\u4e00\u4e2a thread\uff0c\u5c31\u628a\u5176\u5b83\u7684 coroutine \u653e\u5230\u522b\u7684\u7ebf\u7a0b\u4e0a\u8dd1\u3002<\/p>\n<p>\u7136\u540e\u6709\u4e00\u53e5\u8bdd\uff0cThe programmer sees none of this, which is the point. The result, which we call goroutines, &#8230;<\/p>\n<p>\u6240\u4ee5\u603b\u7ed3\u4e00\u4e0b\u5c31\u662f\uff0c\u6709\u4e00\u4e2a\u534f\u7a0b\uff0c\u5b83 block \u4f4f\u4e86\uff08\u6bd4\u5982\u5728 python \u7684 async function \u91cc\u9762\u5199\u4e86\u4e00\u53e5 time.sleep \uff09\uff0c\u8fd9\u6837\u5176\u5b83\u7684\u534f\u7a0b\u5c31\u4e0d\u80fd\u8dd1\u4e86\u5bf9\u5427\uff0c\u90a3\u6211\u4eec\u5199\u4e00\u4e2a\u9ad8\u7ea7\u4e00\u70b9\u7684 runtime\uff0c\u628a\u80fd\u8dd1\u7684\u534f\u7a0b\u653e\u5230\u5176\u5b83 thread \u4e0a\u8dd1\u3002<br \/>\u5e76\u4e14\u628a\u8fd9\u4e9b\u8fc7\u7a0b\u90fd\u9690\u85cf\u8d77\u6765\uff0c\u4ec0\u4e48 yield \u4e4b\u7c7b\u7684\u4e1c\u897f\u90fd\u6ca1\u6709\u4e86\uff0c\u90fd\u662f runtime \u91cc\u9762\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u6240\u4ee5\u8bf4\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8e coroutine \u7684\u60f3\u6cd5\uff0c\u6216\u8005\u8bf4\u662f\u4e00\u4e2a\u7ecf\u8fc7\u4e86\u5927\u6539\u7684 coroutine\uff0c\u8fd8\u4e13\u95e8\u8bf4\u4e86\u8fd9\u4e2a\u4e1c\u897f\u53eb goroutine \u4e0d\u53eb coroutine \u4e86\u3002<\/p>\n<p>\u6240\u4ee5\u8fd8\u662f\u4e0a\u4e00\u6761\u56de\u590d\u91cc\u9762\u8bf4\u7684\uff0c\u5b83\u6539\u5b8c\u4e86\u5c31\u4e0d\u662f coroutine \u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941517\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Yc1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @CRVV \u6211\u660e\u767d\u4f60\u7684\u610f\u601d\uff0c\u4e5f\u4e0d\u7528\u53bb\u7ea0\u7ed3\u540d\u5b57\uff0c\u603b\u4e4b\u90fd\u662f\u5bf9\u7ebf\u7a0b\u7684\u4e00\u4e2a\u5c01\u88c5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941518\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : user8341 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5404\u4f4d\u5927\u4f6c\uff0cgolang \u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f1a\u8c03\u7528 \u8c03\u5ea6\u5668\uff1f<\/p>\n<p>\u6211\u77e5\u9053\u7684\u6709\u4ee5\u4e0b\u8fd9 3 \u4e2a\uff1a<br \/>1. syscall<br \/>2. go \u8bed\u53e5<br \/>3. \u963b\u585e\u8bfb\u5199 chan<\/p>\n<p>\u666e\u901a\u51fd\u6570\u8c03\u7528\u4f1a\u4e0d\u4f1a\u8c03\u7528 \u8c03\u5ea6\u5668\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941519\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : user8341 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\uff0c1.14 \u7248\u52a0\u5165\u4e86\u65f6\u95f4\u7247\uff0c\u65f6\u95f4\u7247\u7528\u5b8c sysmon \u4f1a\u901a\u8fc7\u53d1\u9001 signal \u7ed9\u7ebf\u7a0b\u7684\u65b9\u5f0f\uff0c\u5f3a\u5236\u4e00\u4e2a goroutine \u8c03\u7528 \u8c03\u5ea6\u5668\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941520\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dollar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             brpc \u4e2d\u7684 bthread \u633a\u597d\u7528\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3941521\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : joydee <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u4ee5\u5c1d\u8bd5\u770b\u770b Rangev3 \u4f5c\u8005 Eric Niebler \u7528\u8fc7\u7684 c++ coroutine \u5e93\uff0c\u94fe\u63a5[https:\/\/github.com\/lewissbaker\/cppcoro],\u9075\u4ece C++ coroutines TS N4680,\u4e0d\u8fc7\u4ee3\u7801\u8fd8\u662f\u86ee\u6666\u6da9\u7684\uff0c\u614e\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>c++ \u6709\u6ca1\u6709\u80fd\u591f\u5bf9\u6807 golan&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/180118"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=180118"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/180118\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=180118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=180118"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=180118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}