Rust Concurrent Programming Practical Course

Original link: https://colobu.com/2022/10/13/concurrency-programming-via-rust/

Rust is becoming more and more widely used, especially in the field of system programming that pursues performance, and has recently officially entered the mainline of the Linux kernel and is expected to be officially used in version 6.1.

Although Rust has a unique design concept and excellent performance, it is not easy to learn, and the learning curve is very steep. At the same time, because Rust is not controlled by a certain company like the Go language, it seems to be “Open” in terms of open source, so it is also favored by the majority of developers, contributing many libraries, many of which are high-quality libraries, and even Higher quality and usage than the standard library, which also brings some problems. Other languages, such as Go language, its standard library is quite excellent, such as a bunch of excellent and high-quality concurrency primitives, when developers are developing concurrent programs, when they need synchronous control and task scheduling, the first choice in their minds is For the concurrency primitives of the standard library, I can’t find a suitable concurrency primitive before I go to a third-party library. But Rust is different. Although the standard library also provides some excellent concurrency primitives, they are limited by the characteristics of the language and are quite complicated to use. There are also many third-party libraries that provide better performance or more features or easier to use functions. Therefore, when using Rust to develop concurrent programs, many developers have no way to control the concurrent logic, or have “difficulty in choosing”, so I specially opened a sequence to prepare a systematic introduction to the knowledge of concurrent programming in Rust. More than a hundred short and explicit examples for a comprehensive introduction to concurrent programming in Rust and the use of related libraries: rust programming via rust .

Two years ago, when I first left Weibo, I was very happy to accept Guo Lei’s invitation to take time to organize the Go concurrent programming practice I had done earlier into a Go concurrent programming practice class , and I opened a special column in geek time. , systematically introduces the concurrent programming of Go language, especially various concurrent primitives, from the usage methods, implementation details, historical implementation methods, pits used by each concurrency primitive and so on.

This time, while taking advantage of the National Day holiday, in addition to translating the book “100 go mistakes and how to avoid them” with the industry leaders, I have systematically sorted out the relevant materials of Rust’s concurrent programming and prepared to open a new one. A series that systematically introduces Rust programming knowledge through the serialization of the public account (WeChat Search Expert Geek Circle ).

The writing style this time is different from the style of the Go concurrent programming practical class. First, this time there is a lot of content, and the related concurrency primitives are very rich. Second, this time, we will basically not talk about the details of the implementation of concurrent primitives, but will mainly introduce their functions and usage scenarios. Maybe a special session will be opened. The advanced courses of the previous course will talk about implementation and pitfalls, but this time, we will mainly start with the introduction, so that everyone can understand and be familiar with these concurrency primitives and use them in work.

Basically, I will present the wonderful content to you in the form of one chapter per week.

The current writing is done during business hours. I try to follow this rhythm and complete the weekly plan on weekends. There may be delays, but I try to follow this rhythm.

The most important point is to sort out the outline. Once the outline is sorted out, one third of the work is completed.

If the relevant code is implemented, then the task is completed by one third.

I’m glad that the outline has been completed and the sample code is basically completed, so if you don’t want to read my long-winded text, you can also directly read the sample code on github.

After I posted the source code repository on reddit yesterday, Rust developers (rustaceans) all over the world responded very strongly. They liked and followed, and the repository increased by more than 100 stars overnight. I’m thinking about whether to write English tutorials at the same time when writing Chinese tutorials, so as to appeal to foreign readers.

Overall, I will introduce the knowledge of concurrent programming in Rust from the following aspects:

  • Chapter 1: Thread: Introduce the use of standard library and third-party library threads
  • chapter 2: Thread Pool: Introducing Thread Pool
  • chapter 3: async/await: Introducing the latest in asynchronous programming
  • chapter 4: synchronization primitives: Introduction to synchronization containers and synchronization primitives
  • chapter 5: concurrency collections: describes how to implement thread-safe collections based on the standard library
  • chapter 6: process: process
  • chapter 7: channel: channels, standard and third-party libraries
  • chapter 8: timer/ticker: must master, timer
  • chapter 9: parking_lot: excellent library
  • chapter 10: crossbeam: excellent library
  • chapter 11: rayon: excellent library
  • chapter 12: tokio: excellent library
  • Chapter n: special: Huge number of synchronization libraries implemented for special purposes

Of course, there will be additions and adjustments when writing, but the basic context is like this. If you are interested in concurrent programming in Rust, do not star this repository ( https://github.com/smallnest/concurrency-programming-via-rust) and the public account (**Expert Geek Circle**).

This article is reprinted from: https://colobu.com/2022/10/13/concurrency-programming-via-rust/
This site is for inclusion only, and the copyright belongs to the original author.