Go

Concurrency Patterns & sync Interview Questions

38 Go interview questions on concurrency patterns & sync, with detailed answers and code.

0/577 known
38 questions
Concurrency Patterns & syncQ222Hard

Normal mode: waiters queue in FIFO order, but a woken waiter does not get the lock handed to it. It has to compete with goroutines that are arriving right now, and those…

Concurrency Patterns & syncQ224Medium

type Counter struct { mu sync.Mutex n int } func (c Counter) Inc() { // value receiver c.mu.Lock() defer c.mu.Unlock() c.n++ } func main() { var c Counter var wg…

Concurrency Patterns & syncQ233Hard

var done bool var msg string func setup() { msg = "hello" done = true } func main() { go setup() for !done { } fmt.Println(msg) } No output is guaranteed. This is a data…

Concurrency Patterns & syncQ236Medium

func main() { var wg sync.WaitGroup for i := 0; i < 3; i++ { wg.Add(1) go func() { defer wg.Done() fmt.Print(i, " ") }() } wg.Wait() } Go 1.22 and later (when go.mod…

Concurrency Patterns & syncQ241Medium

func fastest(ctx context.Context, mirrors []string) string { ch := make(chan string) for _, m := range mirrors { go func() { ch <- fetch(ctx, m) }() } return <-ch } Only…

Next topicContext