Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csjgg blog #258

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions source/_posts/csjgg-blog.md
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 了
Loading