Go

Advanced Go

Compiler internals, runtime, scheduler, cgo, unsafe package, assembly, build tags

20 면접 질문·
Senior
1

Which Go toolchain tool allows inspecting the assembly code generated by the compiler?

답변

The go tool compile -S command displays the assembly code generated by the Go compiler. This tool is essential for understanding compiler optimizations and analyzing performance-critical code. It is also possible to use go build -gcflags=-S to achieve the same result during a standard build.

2

What is the main purpose of the unsafe package in Go?

답변

The unsafe package allows bypassing Go's type system to perform low-level memory operations. It exposes functions like Pointer, Sizeof, Alignof, and Offsetof that enable direct memory address manipulation. Its use is discouraged except for specific cases like interoperability with C code or critical optimizations.

3

How does the Go scheduler (GPM) organize goroutine execution?

답변

The Go scheduler uses the GPM model: G represents goroutines, P represents logical processors (GOMAXPROCS), and M represents system threads. Each P has a local run queue of goroutines. When an M is blocked on a syscall, the P can be detached and associated with another M to continue goroutine execution. This design enables efficient scheduling with minimal context switches.

4

What is cgo and in which context should it be used?

5

Which directive allows conditionally compiling code based on target OS or architecture?

+17 면접 질문

다음 면접을 위해 Go을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기