October 17, 2023
Wezterm极简配置文件
-- Pull in the wezterm API local wezterm = require 'wezterm' -- This table will hold the configuration. local config = {} -- In newer versions of wezterm, use the config_builder which will -- help provide clearer error messages if wezterm.config_builder then config = wezterm.config_builder() end -- This is where you actually apply your config choices -- For example, changing the color scheme: config.color_scheme = 'AdventureTime' -- config.color_scheme = 'Batman' config.
...
January 28, 2022
有一些东西,做了一些事情。
有什么东西,做了什么呢?
有文件、结构体、特征、类型,调用了函数、方法,读了文件/读了body,算了结果,写了文件/答了请求。
IO or 计算。
或者说,更强调IO,还是计算。
内存安全 # 并发安全 #
January 10, 2022
crossbeam # crossbeam: Tools for concurrent programming in Rust.
Atomics
Data structures
Memory management: epoch
Thread synchronization: channel, Parker, ShardedLock, WaitGroup
Utilities
channel example # use crossbeam_channel::unbounded; let (s, r) = unbounded(); s.send("Hello, world!").unwrap(); assert_eq!(r.recv(), Ok("Hello, world!")); unbounded(无限) channel发送时不用等接收端就绪。
另外还有bounded channel可在新建时指定容量,后续发送的消息数不能超过该数据 – 除非中间有消息被取走了
当bounded channel容量设为0时,发送前必须等接收端就绪,一般可用于线程间等待。
更多介绍
与标准库的sync::mpsc对比
epoch # Pin 做了什么?
crossbeam在实现无锁并发结构时,采用了基于代的内存回收方式1,这种算法的内存管理开销和数据对象的数量无关,只和线程的数量相关,因此在 以上模型中可以表现出更好的一致性和可预测性。不过Rust中的所有权系统已经保证了内存安全,那为什么还需要做额外的内存回收呢?这个问题的关键点 就在要实现无锁并发结构。如果使用标准库中的Arc自然就不会有内存回收的问题,但对Arc进行读写是需要锁的。
crossbeam-channel文章
digest # This crate provides traits which describe functionality of cryptographic hash functions and Message Authentication algorithms.
...