-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: csjgg_blog | ||
date: 2024-04-24 19:43:22 | ||
tags: rust | ||
--- | ||
|
||
## Begin | ||
|
||
rust 有趣捏 | ||
|
||
## Tips | ||
|
||
### 所有权 | ||
|
||
**关于所有权的规则**: | ||
|
||
1. Rust 中每一个值都被一个变量所拥有,该变量被称为值的所有者 | ||
2. 一个值同时只能被一个变量所拥有,或者说一个值只能拥有一个所有者 | ||
3. 当所有者(变量)离开作用域范围时,这个值将被丢弃(drop) | ||
4. 当值不是可copy的,简单的= 做的是move | ||
5. 如果想要多个变量指向一个值, 通过引用 | ||
6. mut引用只能有一个, 不可变引用可以很多,两者不能同时存在 | ||
|
||
### tokio | ||
|
||
貌似没涉及,但是觉得好玩捏 | ||
|
||
- 底层是线程池+调度器 | ||
- tokio::spawn 出来的task 类似一种协程, 可以被调度器调度 | ||
- 每个task 由诸多future组成, future实际上是一种trait, 实现了它的对象可以被poll, poll它的时候是不阻塞的,如果出现io,返回not ready | ||
- 每个线程维护task队列, 用完时可以偷取其他线程的 | ||
- 非阻塞io的底层实现是epoll, 当epoll返回时,调度器会选择调度 | ||
|
||
## End | ||
|
||
谢谢THU捏 | ||
|
||
太喜欢rust 了 |