[Solved] For a concurrent download handler does this create a race condition?

As you can tell from some of the comments, multithreaded code is serious business. It’s best to follow a proven pattern, e.g. producer-consumer, or at least use an established synchronization primitive like a monitor or semaphore. Because I might be wrong. It is easy to go over code that you came up with yourself and … Read more

[Solved] Java: two threads executing until the boolean flag is false: the second thread’s first run stops the first thread

this just isn’t how you’re supposed to work with threads. You have 2 major problems here: java memory model. Imagine that one thread writes to some variable, and a fraction of a second later, another thread reads it. If that would be guaranteed to work the way you want it to, that means that write … Read more

[Solved] How to make an api call faster in Golang?

Consider a worker pool pattern like this: https://go.dev/play/p/p6SErj3L6Yc In this example application, I’ve taken out the API call and just list the file names. That makes it work on the playground. A fixed number of worker goroutines are started. We’ll use a channel to distribute their work and we’ll close the channel to communicate the … Read more

[Solved] Select statement channel example

The select statement chooses a case whose communication op would not block. If there are multiple cases whose comm. op would not block, one is chosen randomly. Since in the example all communication ops would block, and since a default is provided, that will be executed. To “trigger” another case, you have to make sure … Read more

[Solved] How can I overlap goroutines?

If you need such sequencing, you might reevaluate your need to use goroutines. However, the way you described the solution is correct: go first() { for { <-ch1 // do stuff ch2<-struct{}{} } }() go second() { for { <-ch2 // do stuff ch3<-struct{}{} } }() go third() { for { <-ch3 // do stuff … Read more