#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Concurrency

Concurrency in Go – Goroutines and Sync.WaitGroup Tutorial

What is a Goroutine?

A goroutine is a lightweight thread managed by the Go runtime, letting functions run concurrently with very low overhead.

func sayHello() {
    fmt.Println("Hello from goroutine")
}

go sayHello() // runs concurrently

Waiting for Goroutines with sync.WaitGroup

Since the main function doesn't wait for goroutines by default, sync.WaitGroup is used to block until a group of goroutines finishes.

var wg sync.WaitGroup

for i := 1; i <= 3; i++ {
    wg.Add(1)
    go func(id int) {
        defer wg.Done()
        fmt.Println("Worker", id, "done")
    }(i)
}

wg.Wait() // blocks until all goroutines call Done()

Why Goroutines Matter

Goroutines make it easy to write highly concurrent programs — handling thousands of simultaneous tasks with far less memory overhead than traditional OS threads.

Ready to master real-world Go skills?

Learn Go hands-on with mentor-led, live sessions.

Explore Course