Detailed analysis of the source code of Go sync.Mutex

Introduction to Mutex The Mutex structure contains two fields. Field state: indicates the current state of the mutex lock. Field sema: is a semaphore variable to control blocking hibernation and wake-up of waiting goroutines. 1 2 3 4 type Mutex struct { state int32 sema uint32 } In version 1.9 of Go, in order to solve the waiting goroutine may have been unable to obtain the lock, the hunger mode

Detailed analysis of the source code of Go sync.Pool

Introduction to Pool Go is known to be an automatic garbage collection programming language that uses a three-color concurrent tagging algorithm to tag objects and recycle them. If you want to develop a high-performance application using Go, you have to consider the performance impact of garbage collection. Because Go has a STW (stop-the-world) time during garbage collection, and it takes time to mark objects if there are too many. So

MIT introduces Twist, a programming language for quantum computing

Scientists at MIT’s Computer Science and Artificial Intelligence (CSAIL) have developed a new programming language for quantum computing – Twist, specifically designed to solve the data entanglement problem, which could help developers reduce errors and improve data quality. Unlike traditional computers that use bits, quantum computers use quantum bits to encode information as 0 or 1, or both. traditional programming languages are not applicable to quantum computers, which require an appropriate programming language for developers to take advantage of their capabilities.

Detailed analysis of the Channel source code in Go

chan introduction 1 2 3 4 5 6 7 8 9 10 11 12 13 14 package main import "fmt" func main() { c := make(chan int) go func() { c <- 1 // send to channel }() x := <-c // recv from channel fmt.Println(x) } We can view the assembly results like this. 1 2 3 4 go tool compile -N -l -S hello.go -N表示

Thinking about memory alignment by WaitGroup in Go

We all know how to use WaitGroup, but we also need to know how it is implemented, so that we can avoid the panic caused by incorrect use in the project as much as possible, and this article will also write about the memory alignment aspect to do a resolution, I hope you like it. WaitGroup Introduction WaitGroup provides three methods. 1 2 3 func (wg *WaitGroup) Add(delta int) func

Atomic atomic classes and their underlying principles CAS

Introduction Atomic means that an operation is uninterruptible. Even when multiple threads are executing together, once an operation is started, it is not interrupted by other threads. So: atomic classes are classes that have the characteristics of atomic/atomic operations. The atomic classes of the concurrency package JUC(java.util.concurrent) are all in java.util.concurrent.atomic. Example Run the following code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Explaining the Golang memory allocation implementation from source code

Introduction The Go language’s memory allocator takes its cue from TCMalloc’s design for high-speed memory allocation. The core idea is to use a multi-level cache to sort objects by size and implement different allocation strategies by class. Information about TCMalloc can be found here: http://goog-perftools.sourceforge.net/doc/tcmalloc.html. If the object to be allocated is a small object (<= 32k), there is a lock-free cache of small objects in each thread that can

Explaining the Golang I/O multiplexing netpoller model

The Go source code directory structure and corresponding code files provide an insight into Go’s implementation of network I/O modes on different platforms. For example, it is based on epoll on Linux, kqueue on freeBSD, and iocp on Windows. Since our code is deployed on Linux, this article uses the epoll wrapper implementation as an example to explain the source code implementation of I/O multiplexing in Go. Introduction I/O multiplexing

Implementation of the time wheel in the Golang

Recently I had a requirement at work, which simply means that millions of timer tasks will be created in a short period of time, and the corresponding amounts will be added up when they are created to prevent overselling, and the data will need to be checked again after half an hour, and if the data does not match, the added amount will need to be subtracted back. This is

Explaining the Golang dispatch loop source code implementation

Overview When we think of “scheduling”, the first thing that comes to mind is the scheduling of processes and threads by the operating system. The operating system scheduler schedules multiple threads on the system to run on the physical CPU according to a certain algorithm. Although threads are relatively lightweight, they do have a large additional overhead when scheduling. Each thread takes up more than 1M of memory space, and

Golang implementation of cuckoo filters

Introduction In our work, if we encounter such things as web URL de-duplication, spam identification, or the determination of duplicate elements in a large collection, we usually think of saving all the elements in the collection and then determining them by comparison. If we use the best performance Hash table to make the determination, then as the number of elements in the collection increases, the storage space we need will

The principle of timer implementation in Go and source code analysis

Introduction Version 1.13 timers Go uses 64 minimal heaps until version 1.14. All timers created at runtime are added to the minimal heap, and timers created by each processor (P) are maintained by the corresponding minimal heap. The following is the source code for version 1.13 of runtime.time. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

Microsoft Announces VSCode Java 2022 Roadmap

Recently, Microsoft revealed the Visual Studio Code Java development roadmap for 2022 in a developer blog and below is an overview image posted by Microsoft outlining the improvements and changes they will be making in 2022. The image is relatively concise, so follow along to see exactly what changes are in store for each item. According to Microsoft, in 2021, more than 1.5 million developers will be developing in Java in VS Code.

Go language GC implementation principle and source code analysis

20,000 words long article takes you from the source code to dissect the Go language GC implementation. Introduction Three-color marking method The three-color marking method divides the color of the object into three colors: black, gray, and white. Black: the object has been marked and all the properties under the object have been marked (the object required by the program). gray: the object has been marked, but the properties under

Signal-based preemptive scheduling in Go dissected from source code

Introduction Prior to 1.14 of Go, preemptive scheduling was collaborative and required self-initiated ceding of execution, but this could not handle edge cases that could not be preempted. Some of these problems were not solved until 1.14 by signal-based preemptive scheduling, such as for loops or garbage collection of long-running threads. Here is an example to verify the difference in preemption between 1.14 and 1.13. 1 2 3 4 5

Startpage Search Engine Launches Open Source Browser Extension to Protect Users' Private Data

Startpage is a privacy-focused search engine, launched in 1998 by the Dutch company Startpage B.V. Startpage uses the Google search API in its backend, so it has the same search quality as Google. However, it only sends search keywords to Google’s servers and Google does not get any other information than that. Recently Startpage released an open source browser extension (based on GPLv3) for Firefox and Chrome – Startpage Privacy Protection.

What can we learn from TiDB?

What is TiDB TiDB is an open source distributed relational database designed and developed by PingCAP, which is a converged distributed database product that supports both Online Transaction Processing and Online Analytical Processing (HTAP). Five core features One-click horizontal scaling or shrinking: On-demand online scaling or shrinking of compute and storage respectively, transparent to application operators and maintenance personnel during scaling or shrinking. Financial High Availability: Data replicas are synchronized with transaction logs via Multi-Raft protocol, and only commits when most transactions are written successfully, ensuring strong data consistency and not affecting data availability when a few replicas fail.

How to compile and debug Go runtime source code

Compile and modify Golang source code for debugging First download and compile I’m using a centos environment, so I need to install yum -y install gcc first. Then download the go source code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [root@localhost src]# git clone https://github.com/golang/go.git #进入到src 目录执

An article to help you understand stack operations in Go

This article will teach you how to understand Go’s plan9 assembly through stack operations. Knowledge points Linux process in memory layout Each process in a multitasking operating system runs in its own memory sandbox. In 32-bit mode, it is always 4GB of memory address space, and memory allocation is to allocate virtual memory to processes. When a process actually accesses a virtual memory address, the OS allocates a corresponding space

Understanding Go function calls from the stack

This time together, we will understand common function calls, struct method calls, and closure calls in depth assembly from the stack perspective. Preamble Function call types Functions in this article refer to any executable block of code in Go. As mentioned in Go 1.1 Function Calls, there are four types of functions in Go. top-level func method with value receiver method with pointer receiver func literal top-level func is what