I wrote a simple go program which launches about 100 goroutines... I compiled and ran the code and when I ran htop I found way too many (definitely greater 30, I did not count ...) entries of the process I was running. I thought the whole idea of goroutines was to schedule a bunch of goroutines on to a single thread.. (may be two in my case since I am running a dual core machine) .. Am I missing something..?
> It looks like it does create additional threads if one of the
> goroutines blocks due to system/IO and runs the other goroutines on
> these new threads.
>
> Thanks,
> Sunil.
I/O will (generally, I'm not sure if there are exceptions) create a
maximum of one blocked thread, which uses non-blocking I/O as
appropriate to the OS, waking up the appropriate goroutine when it is
done. This makes it cheap to use a goroutine per FD design.
You're right that syscalls in general will block a thread, though.
GOMAXPROCS only affects the number of running threads, not blocked
threads.