Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
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, ...
Tarun Kavipurapu's user avatar
-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 := ...
Hari's user avatar
  • 1,593
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 := ...
iwa2no's user avatar
  • 23
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 ...
Eshant Gupta's user avatar
-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)...
Shankhashuvro Sinha's user avatar
2 votes
1 answer
81 views

Go Program Stuck at syscall.Wait4 in Concurrent Forking Loop

I'm working on a Go program that creates child processes using syscall.RawSyscall(syscall.SYS_FORK) in a concurrent loop. Each child process needs to execute a command (/bin/ls) with specific seccomp ...
zyk2507's user avatar
  • 103
1 vote
0 answers
26 views

Executing Multiple Instances of Code Snippet at Specific Intervals Using Constant Timestamp

I need to run multiple instances of the same code snippet at regular intervals. For example, I want to run four instances, where the first instance starts executing 5 seconds after a constant ...
schrute08's user avatar
0 votes
1 answer
65 views

Why a Timer variable assigned with time.Afterfunc executes its function even though outer func exits

I have a forever loop that has a Timer variable that executes a function after some time. package main import ( fmt "fmt" "time" ) func exe() { fmt.Println("10-...
baris's user avatar
  • 247
-3 votes
1 answer
63 views

Why is this concurrent code slower than the serial code? (Go) [closed]

I wanted to try using a concurrent solution to problem 206 (Reverse a Linked List) on LeetCode, so I wrote this: func reverseList(head *ListNode) *ListNode { var prev, temp *ListNode cur, ch :=...
Boris Kaptsanov's user avatar
1 vote
3 answers
536 views

Go using range to loop over channel, why does it terminate before receiving all the values?

This code is a modified version of a program from section 8.4 of "The Go Programming Language" book. package main import ( "fmt" ) func main() { naturals := make(chan int) ...
Navid's user avatar
  • 23
0 votes
2 answers
69 views

Simpler Golang Concurrency Pattern

I've been trying to make a function that makes multiple external api calls concurrent with the following in mind return the first error encountered aggregate the results of the api call Here is my ...
Jemilu Mohammed's user avatar
0 votes
0 answers
75 views

What is a reasonable number of goroutines I should use to operate on a huge payload size?

I want to implement partial response in my server to be able to do something like this: So, I have a function that's called: func DoPartial[T any](payload []T, fields string...) []map[string]any { /...
alx06's user avatar
  • 19
0 votes
0 answers
47 views

Golang concurrency deadlocks as soon as I add a channel for response

I got a function that is supposed to retrieve information in a goroutine and send it back to the channel as it finishes. func getTopLikeSupporter(username string, session Session, session1 Session) ([]...
Cede's user avatar
  • 11
0 votes
0 answers
44 views

How to get rid of Go routine "process" after the GO routine times out?

I have an interesting challenge. I have a go routine that should display an error message for 4 seconds or until I press any key. If I press a key within the 4 seconds it works as expected but if I ...
sudeki's user avatar
  • 11
-3 votes
1 answer
73 views

Why does this print 0?

i am experimenting with go concurrency and i was trying a few patterns. i was trying this where you receive an array of elements, process them concurrently and sum all the results. i am using 2 ...
Eduardo Díaz's user avatar

15 30 50 per page
1
2 3 4 5
30