In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "go language how to achieve two collaborative process alternating printing", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "go language how to achieve two collaborative process alternating printing" article.
Method 1: use two channel
Channel CA must have a buffer here, or it will end up with an error fatal error: all goroutines are asleep-deadlock!
This is because the unbuffered channel can be sent successfully only when the receiver can receive the value, otherwise it will always be in the stage of waiting for transmission. Because there is no co-program to receive data from the CA channel after the last alternate run, the deadlock will always be blocked.
Package mainimport ("fmt"sync") var wg sync.WaitGroupvar CA chan intvar CB chan intfunc main () {wg = sync.WaitGroup {} CA = make (chan int,1) CB = make (chan int) wg.Add (2) go A () go B () CA
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.