Runtime

go runtime chan

February 11, 2022
Go, Runtime, Chan
Chan

src/runtime/chan.go: // Invariants: // At least one of c.sendq and c.recvq is empty, // except for the case of an unbuffered channel with a single goroutine // blocked on it for both sending and receiving using a select statement, // in which case the length of c.sendq and c.recvq is limited only by the // size of the select statement. // // For buffered channels, also: // c.qcount > 0 implies that c. ...

wasm运行时wasmtime

January 28, 2022
Wasi, Wasm, Runtime
Wasmtime

源码 # # 下载 git clone git@github.com:bytecodealliance/wasmtime.git # 子模块 git submodule update --init --recursive # 安装 cargo build 如果忘了拉子模块,vscode的rust-analyzer会报错,导致智能提示等功能失效。 不过整个初始化过程还是有点长,等了好久才能正常使用。 阅读 # 从build.rs开始,首先映入眼帘的是use anyhow::Context;: /// Provides the `context` method for `Result`. /// /// This trait is sealed and cannot be implemented for types outside of /// `anyhow`. 这是一个为其它类型(anyhow::Result)引入context方法的特征啊,多么伟大,在anyhow包外面的类型就不要想着去实现它了,你们高攀不起的。 再看anyhow::Context的定义: // lib.rs:598 pub trait Context<T, E>: context::private::Sealed { // 继承了Sealed,那它又是怎么样的、做什么的呢? /// Wrap the error value with additional context. -- 给error值包装上下文信息 fn context<C>(self, context: C) -> Result<T, Error> where C: Display + Send + Sync + 'static; // 能展示,并发安全,全局可见的类型值 /// Wrap the error value with additional context that is evaluated lazily /// only once an error does occur. ...