Skip to content

Go Language

Prerequisite of Go Sync Mutex Implementation

This blog is split from the blog of sync mutex implementation due to its length. For better reading experience and clearer organization, it's reasonable to make these background knowledge a separated article.

This blog introduces the language level instructions/functions such as atomic and synchronization, the runtime spinning, sleeping and awoken. It also briefs the memory barrier and assembly code in golang.

Go Program Out of Memory

Last week, during on duty, one user reported his program exited silently without any useful information during deployment, the process is aborted with a killed information:

[1]    90616 killed     ./bin/server

This is an intrigue question as why the program is killed by OOM killer instead of a fatal stack overflow error.

Go Reflect: Fail to Set Argument Value During Conversion

This blog records the failure when trying to set the response value using reflect to provide an adaptor for wrapping the original PRC interceptor to the custom interceptor format defined by our tech products.

The difference between them is the custom interceptor moves the response from an argument to a response. This blog introduces the challenges encountered while designing an adaptor.

Signatures of Original RPC Interceptor And Custom Interceptor
// package rpc
// original RPC interceptor signature
type Interceptor func(ctx context.Context, 
    request, response interface{}, processor Processor) uint32
type Processor func(ctx context.Context, request, response interface{}) uint32


// package custom
// interceptor in the tech team
type CustomInterceptor interface {
    Wrap(HandlerFn) HandlerFn
}
type HandlerFn func(ctx context.Context, req interface{}) (interface{}, error)

Go Function Return Values: List, Not Tuple

Recently, I suddenly found that the following code line is weird, how could it pass (int, error) to ...any?

func main
func variadic(a ...any) {
    fmt.Println(a)
    return
}

func array(a []any) {
    fmt.Println(a...)
    return
}

func main() {
    variadic(json.Marshal(""))
    // array(json.Marshal(""))
    // ^ CANNOT PASS COMPILE
}

Symbol Table and Context Value Implementation

After learning briefly about compiler, with the motivation of walker inside astjson, it's a bit compulsory to master some knowledge about symbol table as it helps to understand management of variables/states in a large different scales.

This blog talks first about the symbol table itself, and then check how Go language maintains the values among contexts in src/context. Note that it doesn't talk anything else rather than values in context.