On Thu, Nov 1, 2018 at 7:24 AM, Michael MacInnis
<michael.p.macin...@gmail.com> wrote:
>
> While running a Go program that uses Cgo, I noticed a surprising number of
> threads. I believe the code below demonstrates what I'm seeing minus (what I
> hope are) extraneous details.
>
> package main
>
> // #include <unistd.h>
> import "C"
>
> func main() {
>     for {
>         C.nanosleep(&C.struct_timespec{tv_sec: 0, tv_nsec: 10000}, nil)
>     }
> }
>
> If I run this program with GOMAXPROCS=1, I see 4 threads (as reported by
> top). I was expecting that number to be closer to 2.
>
> I'm compiling with go 1.11.1 on linux/amd64.

Every blocking cgo call requires a thread.  Also every Go program has
a supporting thread that monitors the programs.  If you see only 4
threads for that program then I think we're doing pretty well.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to