Choosing thread for goroutine?

120 views
Skip to first unread message

Matt Mueller

unread,
Jul 19, 2020, 2:48:16 PM7/19/20
to golang-nuts
Hey folks,

I'm working on a server-side Javascript rendering package in Go. It uses https://bellard.org/quickjs/ for it's parser and interpreter. I'm using https://github.com/lithdew/quickjs to package it with Go.

Quickjs appears to have some thread-local memory, so I'm use runtime.LockOSThread() to make sure that the goroutine is always placed on the same thread. I'm using a worker pattern to distribute load.

The problem I'm running into is that sometimes worker's goroutines get scheduled (and then locked) to the same thread, effectively serializing the computation. This seems random and causes a loss in parallelism since these goroutines will remain on the same thread through their lifetime.

Are there any workarounds with this issue?

Thanks!
Matt


Ian Lance Taylor

unread,
Jul 19, 2020, 6:37:00 PM7/19/20
to Matt Mueller, golang-nuts
In this kind of pattern I would expect that the very first thing the
new goroutine would do would be to call runtime.LockOSThread, and to
only call UnlockOSThread when the goroutine is ready to quit. In that
case I don't see how what you describe could happen. Can you describe
your calling pattern in more detail?

Ian
Reply all
Reply to author
Forward
0 new messages