tezvyn:

cgo threading challenges with multi-threaded C libraries

Source: interviewintermediate

WHAT IT TESTS: understanding of the Go-to-C boundary and threading. OUTLINE: cgo calls run on a dedicated OS thread and detach the P; thread-local state and callbacks into Go are fragile; solutions include LockOSThread, minimizing crossings, and a dedicated…

WHAT IT TESTS: whether you understand the friction between Go's M:N scheduler and C's 1:1 thread model across cgo. ANSWER OUTLINE: A cgo call blocks the calling goroutine's OS thread and the runtime hands its P off, and C code cannot be scheduled by Go. Challenges: thread-local storage in the C library is unreliable because a goroutine may run on different threads; callbacks from C into Go are costly and constrained; signal handling and thread affinity conflict.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

cgo threading challenges with multi-threaded C libraries · Tezvyn