Re:Purego – A library for calling C functions from Go withou...
by totallygamerjet on Sunday February 12, 2023 @12:16PM
(#34764611)
Yeah the default behavior is to switch back. It’s possible to pin a goroutine to a thread with runtime.LockOSThread(). However I don’t believe it avoids the stack switching. It’s purpose it to make sure that Thread Local Storage works properly. The runtime is pretty smart though so it might already do the optimization you suggested in someway. I know it has a goroutine specifically for monitoring if a thread is stuck in a external call and therefore spawns a new thread to continue work (sysmon)
[ Parent
| on HN ]
Re:Purego – A library for calling C functions from Go withou...
by slimsag on Sunday February 12, 2023 @12:23PM
(#34764677)
Ahh that's right, I see.
Maybe I should play with removing the stack switching from purego so that under condition of a locked OS thread you can avoid that overhead :) I might give that a shot sometime