{"id":408,"date":"2022-08-04T17:16:05","date_gmt":"2022-08-04T09:16:05","guid":{"rendered":"https:\/\/www.db2go.net\/?p=408"},"modified":"2022-08-04T17:16:05","modified_gmt":"2022-08-04T09:16:05","slug":"go1-18%e5%89%8d%e7%9a%84%e9%87%8d%e5%85%a5%e9%94%81%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.db2go.net\/?p=408","title":{"rendered":"Go1.18\u524d\u7684\u91cd\u5165\u9501\u5b9e\u73b0"},"content":{"rendered":"<p>\u867d\u7136\u6807\u51c6\u5e93 Mutex\u4e0d\u662f\u53ef\u91cd\u5165\u9501\uff0c\u4f46\u662f\u53ef\u4ee5\u81ea\u5df1\u5b9e\u73b0\u53ef\u91cd\u5165\u7684Mutex\u3002\u53ef\u91cd\u5165\u9501\u5b9e\u73b0\u7684\u5173\u952e\u70b9\u662f\u8ba9\u9501\u5177\u6709\u8bb0\u5f55\u5f53\u524d\u534f\u7a0b\u6301\u6709\u8fd9\u4e2a\u9501\u7684\u80fd\u529b\u3002\u9664\u4e86\u4ee5hack\u7684\u65b9\u5f0f\u5728\u7f16\u8bd1\u9636\u6bb5\u8ba1\u7b97\u504f\u79fb\u91cf\uff0c\u6dfb\u52a0goroutineid\u5916\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528<code>runtime.Stack<\/code>\u51fd\u6570\u83b7\u53d6\u5e76\u8bb0\u5f55\u5230goroutineid\uff0c\u8bb0\u5f55\u4e0b\u83b7\u53d6\u9501\u7684 goroutineid\uff0c\u5b83\u53ef\u4ee5\u5b9e\u73b0 Locker \u63a5\u53e3\u3002\u5173\u952e\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-go line-numbers\"> n := runtime.Stack(buf[:], false)\n\/\/ \u5f97\u5230goroutineid\ngidStr := strings.Fields(strings.TrimPrefix(string(buf[:n]), \"goroutine\"))[0]\ngid, err := strconv.Atoi(gidStr)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u867d\u7136\u6807\u51c6\u5e93 Mutex\u4e0d\u662f\u53ef\u91cd\u5165\u9501\uff0c\u4f46\u662f\u53ef\u4ee5\u81ea\u5df1\u5b9e\u73b0\u53ef\u91cd\u5165\u7684Mutex\u3002\u53ef\u91cd\u5165\u9501\u5b9e\u73b0\u7684\u5173\u952e\u70b9\u662f\u8ba9\u9501\u5177\u6709\u8bb0\u5f55\u5f53\u524d&hellip;<\/p>\n <a href=\"https:\/\/www.db2go.net\/?p=408\" title=\"Go1.18\u524d\u7684\u91cd\u5165\u9501\u5b9e\u73b0\" class=\"entry-more-link\"><span>Read More<\/span> <span class=\"screen-reader-text\">Go1.18\u524d\u7684\u91cd\u5165\u9501\u5b9e\u73b0<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[12],"tags":[],"class_list":["entry","author-suredandan","post-408","post","type-post","status-publish","format-standard","category-golang"],"views":1504,"_links":{"self":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=408"}],"version-history":[{"count":1,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/408\/revisions"}],"predecessor-version":[{"id":409,"href":"https:\/\/www.db2go.net\/index.php?rest_route=\/wp\/v2\/posts\/408\/revisions\/409"}],"wp:attachment":[{"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.db2go.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}