On Tue, Jun 20, 2023 at 3:36 PM robert engels <reng...@ix.netcom.com> wrote:
>
> Since this is an initialization guard - can’t it simply be double checked 
> with an atomic flag?

That would be a good first thing to try.

Ian


> > On Jun 20, 2023, at 9:04 AM, Ian Lance Taylor <i...@golang.org> wrote:
> >
> > On Tue, Jun 20, 2023 at 5:32 AM Bảo Phan Quốc <phq...@gmail.com> wrote:
> >>
> >> I'm using cgo to call a C function from Go. Inside the C function there is 
> >> a callback to a Go function. In other way, I'm calling Go -> C -> Go.
> >>
> >> After running pprof, I noticed that the __GI___pthread_mutex_unlock took 
> >> half of the execution time. AFAIK, cgo has an overhead, especially calling 
> >> back from C to Go. But it's weird that cgo takes half of the execution 
> >> time to do some locking. Is there something wrong in my code?
> >
> > Every call from C to Go does acquire a mutex to check that the Go
> > runtime has been fully initialized.  This is normally not a big deal
> > as the mutex is held only briefly.  But your code does a lot of
> > parallel calls from C to Go.  It is possible that the heavy contention
> > on the mutex is causing the results that you are seeing.
> >
> > The code in question is the C function _cgo_wait_runtime_init_done in
> > runtime/gco/gcc_libinit.c.  It might be possible to speed it up in
> > some way to avoid the mutex in the normal case.
> >
> > 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.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU7Csb_hf5gvy8dVHKEHd8GFkN-fUML18uW0HiQGOAXyg%40mail.gmail.com.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWDPzyR9wS8na6eexkeLtus%2BTWCjsmVObuj8QgD95rJ-Q%40mail.gmail.com.

Reply via email to