go - Benefits of runtime.LockOSThread in Golang -


golang supports lockosthread() make current goroutine exclusively tied current os thread, , can unlockosthread().

are there use cases benefit feature?

with go threading model, calls c code, assembler code, or blocking system calls occur in same thread calling go code, managed go runtime scheduler.

the os.lockosthread() mechanism useful when go has interface foreign library (a c library instance). guarantees several successive calls library done in same thread.

this interesting in several situations:

  • a number of graphic libraries (os x cocoa, opengl, sdl, ...) require calls done on specific thread (or main thread in cases).

  • some foreign libraries based on thread local storage (tls) facilities. store context in data structure attached thread. or functions of api provide results memory lifecycle attached thread. concept used in both windows , unix-like systems. typical example errno global variable commonly used in c libraries store error codes. on systems supporting multi-threading, errno defined thread-local variable.

  • more generally, foreign libraries may use thread identifier index/manage internal resources.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -