Questions tagged [waitgroup]
42 questions
1
vote
1 answer
Code executes successfully even though there are issues with WaitGroup implementation
I have this snippet of code which concurrently runs a function using an input and output channel and associated WaitGroups, but I was clued in to the fact that I've done some things wrong. Here's the code:
func main() {
concurrency := 50
var…
user17699298
1
vote
2 answers
Running a maximum of two go routines continuously forever
I'm trying to run a function concurrently. It makes a call to my DB that may take 2-10 seconds. I would like it to continue on to the next routine once it has finished, even if the other one is still processing, but only ever want it be processing…

Nicole Staline
- 557
- 4
- 15
1
vote
0 answers
Need help syncing: WaitGroup
I would like your help, here is a piece of code in which requests are emitted https://play.golang.org/p/1_FOY8BTZND,each request has its own delay 1 request is waiting for the second to complete, that is wg.Done(), return:
ID: 0, Name: Test #1,…

paymex
- 11
- 2
1
vote
2 answers
sync.WaitGroup initialization before goroutine start
I had the following code as part of a test:
expected := 10
var wg sync.WaitGroup
for i := 0; i < expected; i++ {
go func(wg *sync.WaitGroup) {
wg.Add(1)
defer wg.Done()
// do something
…

learnlearnlearn
- 946
- 1
- 8
- 16
1
vote
1 answer
Understanding goroutines synchronization
I am trying to understand the golang channels and synchronization.
When I run my program with race detector, it results in race detection.
My program:
func main() {
ch := make(chan int)
done := make(chan struct{})
wg :=…

RaceBase
- 18,428
- 47
- 141
- 202
0
votes
2 answers
Safe way to terminate an endlessly looping goroutine?
I have a goroutine that is acting as a listener. A stream of input is coming in on a certain buffered channel, and I want my goroutine to process data as it comes in on that channel. However, there may come a time where no data comes in on that…

ribs2spare
- 229
- 1
- 4
- 12
0
votes
2 answers
Writing to chan within sync.WaitGroup goroutine
I am fetching a list of items from an API endpoint. Then for each item I make another API request to get data about the individual item.
I can't make the second API request for every item concurrently, because my API token has a rate limit and I'll…

ETLJ
- 123
- 1
- 8
0
votes
1 answer
sync: WaitGroup is reused before previous Wait has returned
This code runs concurrently in many goroutines,the following code is a key and relevant part extracted from the production environment code.:
func check() {
.......check condition......
//skipEnsure and skipNative will not both false here
…

jx.wtj
- 29
- 3
0
votes
1 answer
Go WorkGroup doesn't synchronize functions
This is just an abstract example. test will work as long as it receives messages from test2. Then when they are all done wg.Done() will be called, and application will close after wg.Wait().
package main
import (
"fmt"
"sync"
)
var a =…
user21412656
0
votes
3 answers
fatal error: all goroutines are asleep - deadlock | Go Routine
The problem is that both the goOne and goTwo functions are sending values to the channels ch1 and ch2 respectively, but there is no corresponding receiver for these values in the main function. This means that the channels are blocked and the…

Nidhey Indurkar
- 11
- 2
0
votes
1 answer
How to use go-routines while parsing text file for URLs with regex
I've been given a task to search for URLs in text file useng regex and goroutines with waitgroup in the way the given way: text should be devided between N workers (goroutines), each goroutine search for //https://, goroutines in waitgroup, final…

Raptorik
- 11
- 1
0
votes
1 answer
How can serial some goroutings to be finish
I have a Go Project sample, trying to simulate something like baking 1000 pizza concurrency but the oven just has 10 parts to put the pizza. I developed like this, but goroutines are deadlocked. would anyone help
package main
import (
"fmt"
…
0
votes
1 answer
How to make work concurrent while sending data on a stream in golang?
I have a golang grpc server which has streaming endpoint. Earlier I was doing all the work sequentially and sending on the stream but then I realize I can make the work concurrent and then send on stream. From grpc-go docs: I understood that I can…

rosed
- 137
- 8
0
votes
0 answers
Unreliable Termination of Worker Routines Producing Jobs
In an effort to learn more about Golang, I am attempting to fetch match data from an online 5v5 video game.
Based on a given player, I'll request his matchlist and based on the gameIDs within this matchlist I am requesting the metadata for each of…

DwayneHart
- 129
- 1
- 7
0
votes
1 answer
Is there another way to make WaitGroup showed the process?
This is my Snippet Code to run the whole worker
for w := 1; w <= *totalworker; w++ {
wg.Add(1)
go worker(w, jobs, results, dir, &wg)
}
This was my Worker
defer wg.Done()
for j := range jobs {
filename := j[0][4]…

Panji Tri Wahyudi
- 472
- 1
- 9