DEV Community

achraf DEV
achraf DEV

Posted on

Why this simple GO process uses 4 threades?

Exploring Threads in C vs Go — A Curious Experiment 🧵

Recently, I was experimenting with C and Go, and something interesting caught my eye. I wanted to see how many threads each language uses when running a simple program.

So, I wrote two nearly identical programs — one in C and one in Go — compiled and ran them. To my surprise, the C program used only 1 thread, while the Go program spun up 4 threads, even though their logic was exactly the same!

Here’s what I found and how I tested it 👇

Top comments (1)

Collapse
 
vishwaratna profile image
Vishwa Ratna

Your application logic runs on a single thread. The Go runtime, however, may spawn a few additional threads internally (usually 2–4) for tasks like garbage collection and scheduling goroutines, but these are not related to your code.