All Questions
Tagged with concurrency go
1,381
questions
0
votes
1
answer
55
views
Why does the following example with condition variables as synchronization primitives have a data race? [duplicate]
Golang documentation for the condition variables states the following:
In the terminology of the Go memory model, Cond arranges that a call
to Broadcast or Signal “synchronizes before” any Wait call ...
0
votes
1
answer
45
views
What would be the best way to handle many I/O connections in GoLang? [closed]
I'm trying to make a game server in Go that is planned to handle 1~2k connections at a time. The server will read/send tcp packets. The question is when do I need to use a goroutine? Do I use one ...
0
votes
1
answer
35
views
Go channel sometimes not receiving the last value
I'm currently learning go channels, and I'm trying out this piece of code. It creates 10 goroutines which sends a 1000 1s each to a channel. Then another go routine receives it and adds it to a ...
0
votes
0
answers
47
views
Request Chunks from the peer in parallel in golang over a tcp connection
I'm building a P2P file transfer system in Go that fetches chunks of data from peers in parallel. While sequential requests work fine, parallel requests using goroutines behave inconsistently, ...
0
votes
1
answer
65
views
Performance in Go: Mutex vs RWMutex
There are two types of mutex in Go: Mutex and RWMutex
Mutex offers func Lock() and func Unlock().
RWMutex offers those functions plus func RLock() and func RUnlock().
From what I understand, we ...
-1
votes
1
answer
52
views
GO Cond - fmt.Println after wg.Done ended up dead lock
Unable to understand this dead lock situation in golang, i have below to go code with pub and sub pattern
package main
import (
"fmt"
"sync"
)
func main() {
cond := ...
1
vote
1
answer
33
views
How to implement ordered fan-in (proper message passing for my language)?
I'm the creator of https://github.com/nevalang/neva
It's a dataflow programming where you have nodes that do message passing through ports. I use go channels to implement that. However, I faced an ...
-2
votes
0
answers
23
views
Understanding concurrent channel read behavior [duplicate]
I wrote the code below to check the distribution of channel elements between two functions:
package main
import (
"fmt"
)
func a(ch chan int, done chan struct{}) {
for i := range ...
-1
votes
1
answer
55
views
Is sync.Map LoadOrStore subject to race conditions?
I'm using sync.Map's LoadOrStore method in Go. I'm trying to understand if there could be a race condition leading to multiple evaluations of the value creation function. I'm trying to understand if ...
1
vote
1
answer
98
views
Goroutine inside function
I've read https://go.dev/blog/pipelines and there're two functions:
// move numbers into a channel
func gen(nums ...int) <-chan int {
out := make(chan int)
go func() {
for _, n := ...
0
votes
0
answers
58
views
How many go routines will be created at runtime?
In an interview today, I got a problem to write a program with 2 goroutines to generate even and odd sequence and synchronize them to print the sequence of number.
Later, I was asked how many routines ...
1
vote
1
answer
44
views
How to timeout concurrent calls when iterating through a list of items
I was looking into a problem where I need to process a bunch of items in a list. Now I need only the results from the items which can be processed in the configured time, and other results need to be ...
1
vote
1
answer
67
views
Accessing a shared map in go concurrently
I'm new at concurrency and I'm facing the following problem.
I have an external for loop, for getting rows from the database. I want in every single loop to fill the vertexDistribution map
for year := ...
1
vote
0
answers
90
views
How to implement lock-free slice append using CAS in Golang?
again edit:
This is my newest implement code.
The previous code has a race condition when using 'append'.
https://go.dev/play/p/YlJQbnHnhPp
func (group *Actions) Add(key string, action func()) {
...
-1
votes
2
answers
91
views
Why doesn't this Go code create a deadlock?
package main
import (
"fmt"
"sync"
"time"
)
var wg sync.WaitGroup
func main() {
ch := make(chan int) // Declare the channel inside main()
wg.Add(4)...