{"id":256267,"date":"2022-11-17T08:55:14","date_gmt":"2022-11-17T00:55:14","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=256267"},"modified":"2022-10-28T12:56:40","modified_gmt":"2022-10-28T04:56:40","slug":"sync-waitgroup-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sync-waitgroup-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdGo sync WaitGroup\u4f7f\u7528\u6df1\u5165\u7406\u89e3"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86Go sync WaitGroup\u4f7f\u7528\u6df1\u5165\u7406\u89e3\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u501f\u9274\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u591f\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u5927\u5bb6\u591a\u591a\u8fdb\u6b65\uff0c\u65e9\u65e5\u5347\u804c\u52a0\u85aa<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u57fa\u672c\u4ecb\u7ecd<\/strong><\/div>\n WaitGroup\u662fgo\u7528\u6765\u505a\u4efb\u52a1\u7f16\u6392\u7684\u4e00\u4e2a\u5e76\u53d1\u539f\u8bed\uff0c\u5b83\u8981\u89e3\u51b3\u7684\u5c31\u662f\u5e76\u53d1 - \u7b49\u5f85\u7684\u95ee\u9898\uff1a<\/p>\n \u5f53\u6709\u4e00\u4e2a goroutine A \u5728\u68c0\u67e5\u70b9\uff08checkpoint\uff09\u7b49\u5f85\u4e00\u7ec4 goroutine \u5168\u90e8\u5b8c\u6210\uff0c\u5982\u679c\u8fd9\u4e9b goroutine \u8fd8\u6ca1\u5168\u90e8\u5b8c\u6210\uff0cgoroutine A \u5c31\u4f1a\u963b\u585e\u5728\u68c0\u67e5\u70b9\uff0c\u76f4\u5230\u6240\u6709 goroutine \u90fd\u5b8c\u6210\u540e\u624d\u80fd\u7ee7\u7eed\u6267\u884c<\/p>\n \u8bd5\u60f3\u5982\u679c\u6ca1\u6709WaitGroup\uff0c\u60f3\u8981\u5728\u534f\u7a0bA\u7b49\u5230\u5176\u4ed6\u534f\u7a0b\u6267\u884c\u5b8c\u6210\u540e\u80fd\u7acb\u9a6c\u6267\u884c\uff0c\u53ea\u80fd\u4e0d\u65ad\u8f6e\u8be2\u5176\u4ed6\u534f\u7a0b\u662f\u5426\u6267\u884c\u5b8c\u6bd5\uff0c\u8fd9\u6837\u7684\u95ee\u9898\u662f\uff1a<\/p>\n \u800c\u7528WaitGroup\u65f6\uff0c\u534f\u7a0bA\u53ea\u7528\u963b\u585e\uff0c\u76f4\u5230\u5176\u4ed6\u534f\u7a0b\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u518d\u901a\u77e5\u534f\u7a0bA,\u5176\u4ed6\u8bed\u8a00\u4e5f\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u7684\u5de5\u5177\uff0c\u4f8b\u5982Java\u7684CountDownLatch<\/p>\n \u4f7f\u7528<\/strong><\/div>\n Waitgroup\u63d0\u4f9b\u4e863\u4e2a\u65b9\u6cd5\uff1a<\/p>\n func (wg *WaitGroup) Add(delta int)\r\nfunc (wg *WaitGroup) Done()\r\nfunc (wg *WaitGroup) Wait()<\/pre>\n |