Go

Advanced Go

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

20 câu hỏi phỏng vấn·
Senior
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 câu hỏi phỏng vấn

Nắm vững Go cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí