On Sat, Oct 24, 2020 at 10:30 AM ByeongJoon Gong <kongfamily0...@gmail.com> wrote: > > I'm developing speech-to-text inference server with cpp libraries (wav2letter) > > according to runtime docs > (https://golang.org/src/runtime/proc.go?s=108905:108924#L3803), > > "A goroutine should call LockOSThread before calling OS services or non-Go > library functions that depend on per-thread state" > > The current server process as fallow > > func requestHandler(stream grpc....) { > # runtime.LockOSThread() > var decoder unsafe.Pointer > init := false > > defer func() { > if decoder != nil { > C.resetDecoder(decoder) > } > } > for { > in, err := stream.Recv(); // grpc streaming > if err != nil { > break; > } > > if init == true { > C.decode(decoder, someTransformFunc(in.audio)) > } else { > decoder = C.getDecoder() > init = true > } > } > } > > Even if I don't call runtime.LockOSThread(), it works. > but memory leak occured when repeated. > ( VmData keep increasing on /proc/{pid}/status ) > > If I call runtime.LockOSThread(), it works good and no memory leak. > > why does a memory leak occur only when runtime.LockOSThread() is not called?
We don't know because we don't know how the C code works. If it uses per-thread state, then you need to call runtime.LockOSThread in Go. But we don't know what it does. You'll need to look at the C code. 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/CAOyqgcX5gPg3gdm-qoCTca4hv46%3DmrCtH2R%2BQTQ3KO_BV%3DY%2B2g%40mail.gmail.com.