Skip to content

Commit 855619e

Browse files
authored
enhance README.md (#347)
2 parents bc15b2b + 9fee264 commit 855619e

File tree

4 files changed

+220
-243
lines changed

4 files changed

+220
-243
lines changed

CHANGELOG.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
### 0.6.x
2+
3+
- [x] support custom task and coroutine priority.
4+
- [x] support scalable stack
5+
6+
### 0.5.x
7+
8+
- [x] refactor syscall state, distinguish between state and innerState
9+
10+
### 0.4.x
11+
12+
- [x] Supports and is compatible with io_uring in terms of local file IO
13+
- [x] elegant shutdown
14+
- [x] use log instead of println
15+
- [x] enhance `#[open_coroutine::main]` macro
16+
- [x] refactor hook impl, no need to publish dylibs now
17+
- [x] `Monitor` follow the `thread-per-core` guideline
18+
- [x] `EventLoop` follow the `thread-per-core` guideline
19+
20+
### 0.3.x
21+
22+
- [x] ~~support `genawaiter` as low_level stackless coroutine (can't support it due to hook)~~
23+
- [x] use `corosensei` as low_level coroutine
24+
- [x] support backtrace
25+
- [x] support `#[open_coroutine::co]` macro
26+
- [x] refactor `WorkStealQueue`
27+
28+
### 0.2.x
29+
30+
- [x] use correct `epoll_event` struct
31+
- [x] use `rayon` for parallel computing
32+
- [x] support `#[open_coroutine::main]` macro
33+
- [x] hook almost all `read` syscall
34+
<details>
35+
<summary>read syscalls</summary>
36+
37+
- [x] recv
38+
- [x] readv
39+
- [x] pread
40+
- [x] preadv
41+
- [x] recvfrom
42+
- [x] recvmsg
43+
44+
</details>
45+
46+
- [x] hook almost all `write` syscall
47+
<details>
48+
<summary>write syscalls</summary>
49+
50+
- [x] send
51+
- [x] writev
52+
- [x] sendto
53+
- [x] sendmsg
54+
- [x] pwrite
55+
- [x] pwritev
56+
57+
</details>
58+
59+
- [x] hook other syscall
60+
<details>
61+
<summary>other syscalls</summary>
62+
63+
- [x] sleep
64+
- [x] usleep
65+
- [x] nanosleep
66+
- [x] connect
67+
- [x] listen
68+
- [x] accept
69+
- [x] shutdown
70+
- [x] poll
71+
- [x] select
72+
73+
</details>
74+
75+
### 0.1.x
76+
77+
- [x] basic suspend/resume supported
78+
- [x] use jemalloc as memory pool
79+
- [x] higher level coroutine abstraction supported
80+
- [x] preemptive scheduling supported
81+
- [x] work stealing supported
82+
- [x] sleep system call hooks supported

README.md

Lines changed: 38 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@
1010

1111
The `open-coroutine` is a simple, efficient and generic stackful-coroutine library.
1212

13-
<div style="text-align: center;">
14-
<img src="https://github.com/acl-dev/open-coroutine-docs/blob/master/img/architecture.png" width="100%">
15-
</div>
13+
## 🚀 Features
1614

17-
[我有故事,你有酒吗?](https://github.com/acl-dev/open-coroutine-docs)
15+
- [x] Preemptive(`not supported in windows`): even if the coroutine enters a dead loop, it can still be seized, see [example](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/preemptive.rs);
16+
- [x] Hook: you are free to use most of the slow system calls in coroutine;
17+
- [x] Scalable: the size of the coroutine stack supports unlimited expansion, and immediately shrinks to the original size after use, see [example](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/scalable_stack.rs);
18+
- [x] io_uring(`only in linux`): supports and is compatible with io_uring in terms of local file IO and network IO. If it's not supported on your system, it will fall back to non-blocking IO;
19+
- [x] Priority: support custom task and coroutine priority;
20+
- [x] Work Stealing: internally using a lock free work steel queue;
21+
- [x] Compatibility: the implementation of open-coroutine is no async, but it is compatible with async, which means you can use this crate in tokeno/sync-std/smol/...;
22+
- [x] Platforms: running on Linux, MacOS and Windows;
1823

19-
## Status
24+
## 🕊 Roadmap
2025

21-
Still under development, please `do not` use this library in the `production` environment !
26+
- [ ] support `#[open_coroutine::all_join]` and `#[open_coroutine::any_join]` macro to wait coroutines;
27+
- [ ] add synchronization toolkit;
28+
- [ ] support and compatibility for AF_XDP socket;
2229

23-
## How to use this library ?
30+
## 📖 Quick Start
2431

2532
### step1: add dependency to your Cargo.toml
2633

@@ -39,253 +46,41 @@ fn main() {
3946
}
4047
```
4148

42-
### step3: enjoy the performance improvement brought by open-coroutine !
43-
44-
## Examples
45-
46-
### Amazing preemptive schedule
47-
48-
Note: not supported for windows
49+
### step3: create a task
4950

5051
```rust
5152
#[open_coroutine::main]
52-
fn main() -> std::io::Result<()> {
53-
cfg_if::cfg_if! {
54-
if #[cfg(all(unix, feature = "preemptive-schedule"))] {
55-
use open_coroutine_core::scheduler::Scheduler;
56-
use std::sync::{Arc, Condvar, Mutex};
57-
use std::time::Duration;
58-
59-
static mut TEST_FLAG1: bool = true;
60-
static mut TEST_FLAG2: bool = true;
61-
let pair = Arc::new((Mutex::new(true), Condvar::new()));
62-
let pair2 = Arc::clone(&pair);
63-
let handler = std::thread::Builder::new()
64-
.name("preemptive".to_string())
65-
.spawn(move || {
66-
let scheduler = Scheduler::new();
67-
_ = scheduler.submit(
68-
|_, _| {
69-
println!("coroutine1 launched");
70-
while unsafe { TEST_FLAG1 } {
71-
println!("loop1");
72-
_ = unsafe { libc::usleep(10_000) };
73-
}
74-
println!("loop1 end");
75-
1
76-
},
77-
None,
78-
);
79-
_ = scheduler.submit(
80-
|_, _| {
81-
println!("coroutine2 launched");
82-
while unsafe { TEST_FLAG2 } {
83-
println!("loop2");
84-
_ = unsafe { libc::usleep(10_000) };
85-
}
86-
println!("loop2 end");
87-
unsafe { TEST_FLAG1 = false };
88-
2
89-
},
90-
None,
91-
);
92-
_ = scheduler.submit(
93-
|_, _| {
94-
println!("coroutine3 launched");
95-
unsafe { TEST_FLAG2 = false };
96-
3
97-
},
98-
None,
99-
);
100-
scheduler.try_schedule();
101-
102-
let (lock, cvar) = &*pair2;
103-
let mut pending = lock.lock().unwrap();
104-
*pending = false;
105-
// notify the condvar that the value has changed.
106-
cvar.notify_one();
107-
})
108-
.expect("failed to spawn thread");
109-
110-
// wait for the thread to start up
111-
let (lock, cvar) = &*pair;
112-
let result = cvar
113-
.wait_timeout_while(
114-
lock.lock().unwrap(),
115-
Duration::from_millis(3000),
116-
|&mut pending| pending,
117-
)
118-
.unwrap();
119-
if result.1.timed_out() {
120-
Err(std::io::Error::new(
121-
std::io::ErrorKind::Other,
122-
"preemptive schedule failed",
123-
))
124-
} else {
125-
unsafe {
126-
handler.join().unwrap();
127-
assert!(!TEST_FLAG1);
128-
}
129-
Ok(())
130-
}
131-
} else {
132-
println!("please enable preemptive-schedule feature");
133-
Ok(())
134-
}
135-
}
53+
fn main() {
54+
let task = open_coroutine::task!(|param| {
55+
assert_eq!(param, 1);
56+
}, 1);
57+
task.timeout_join(std::time::Duration::from_secs(1)).expect("timeout");
13658
}
13759
```
13860

139-
outputs
140-
141-
```text
142-
coroutine1 launched
143-
loop1
144-
coroutine2 launched
145-
loop2
146-
coroutine3 launched
147-
loop1
148-
loop2 end
149-
loop1 end
150-
```
151-
152-
### Arbitrary use of blocking syscalls
61+
### step4: scalable stack(optional)
15362

15463
```rust
15564
#[open_coroutine::main]
15665
fn main() {
157-
std::thread::sleep(std::time::Duration::from_secs(1));
66+
_ = open_coroutine::task!(|_| {
67+
fn recurse(i: u32, p: &mut [u8; 10240]) {
68+
open_coroutine::maybe_grow!(|| {
69+
// Ensure the stack allocation isn't optimized away.
70+
unsafe { _ = std::ptr::read_volatile(&p) };
71+
if i > 0 {
72+
recurse(i - 1, &mut [0; 10240]);
73+
}
74+
})
75+
.expect("allocate stack failed")
76+
}
77+
println!("[coroutine] launched");
78+
// Use ~500KB of stack.
79+
recurse(50, &mut [0; 10240]);
80+
}, ());
15881
}
15982
```
16083

161-
outputs
162-
163-
```text
164-
nanosleep hooked
165-
```
166-
167-
## Features
168-
169-
### todo
170-
171-
- [ ] support and compatibility for AF_XDP socket
172-
- [ ] hook other syscall maybe interrupt by signal
173-
<details>
174-
<summary>syscalls</summary>
175-
176-
- [ ] open
177-
- [ ] chdir
178-
- [ ] chroot
179-
- [ ] readlink
180-
- [ ] stat
181-
- [ ] dup
182-
- [ ] dup2
183-
- [ ] umask
184-
- [ ] mount
185-
- [ ] umount
186-
- [ ] mknod
187-
- [ ] fcntl
188-
- [ ] truncate
189-
- [ ] ftruncate
190-
- [ ] setjmp
191-
- [ ] longjmp
192-
- [ ] chown
193-
- [ ] lchown
194-
- [ ] fchown
195-
- [ ] chmod
196-
- [ ] fchmod
197-
- [ ] fchmodat
198-
- [ ] semop
199-
- [ ] ppoll
200-
- [ ] pselect
201-
- [ ] io_getevents
202-
- [ ] semop
203-
- [ ] semtimedop
204-
- [ ] msgrcv
205-
- [ ] msgsnd
84+
## ⚓ Learn
20685

207-
</details>
208-
- [ ] support `#[open_coroutine::join]` macro to wait coroutines
209-
210-
### 0.6.x
211-
212-
- [x] support custom task and coroutine priority.
213-
- [x] support scalable stack
214-
215-
### 0.5.x
216-
217-
- [x] refactor syscall state, distinguish between state and innerState
218-
219-
### 0.4.x
220-
221-
- [x] Supports and is compatible with io_uring in terms of local file IO
222-
- [x] elegant shutdown
223-
- [x] use log instead of println
224-
- [x] enhance `#[open_coroutine::main]` macro
225-
- [x] refactor hook impl, no need to publish dylibs now
226-
- [x] `Monitor` follow the `thread-per-core` guideline
227-
- [x] `EventLoop` follow the `thread-per-core` guideline
228-
229-
### 0.3.x
230-
231-
- [x] ~~support `genawaiter` as low_level stackless coroutine (can't support it due to hook)~~
232-
- [x] use `corosensei` as low_level coroutine
233-
- [x] support backtrace
234-
- [x] support `#[open_coroutine::co]` macro
235-
- [x] refactor `WorkStealQueue`
236-
237-
### 0.2.x
238-
239-
- [x] use correct `epoll_event` struct
240-
- [x] use `rayon` for parallel computing
241-
- [x] support `#[open_coroutine::main]` macro
242-
- [x] hook almost all `read` syscall
243-
<details>
244-
<summary>read syscalls</summary>
245-
246-
- [x] recv
247-
- [x] readv
248-
- [x] pread
249-
- [x] preadv
250-
- [x] recvfrom
251-
- [x] recvmsg
252-
253-
</details>
254-
255-
- [x] hook almost all `write` syscall
256-
<details>
257-
<summary>write syscalls</summary>
258-
259-
- [x] send
260-
- [x] writev
261-
- [x] sendto
262-
- [x] sendmsg
263-
- [x] pwrite
264-
- [x] pwritev
265-
266-
</details>
267-
268-
- [x] hook other syscall
269-
<details>
270-
<summary>other syscalls</summary>
271-
272-
- [x] sleep
273-
- [x] usleep
274-
- [x] nanosleep
275-
- [x] connect
276-
- [x] listen
277-
- [x] accept
278-
- [x] shutdown
279-
- [x] poll
280-
- [x] select
281-
282-
</details>
283-
284-
### 0.1.x
285-
286-
- [x] basic suspend/resume supported
287-
- [x] use jemalloc as memory pool
288-
- [x] higher level coroutine abstraction supported
289-
- [x] preemptive scheduling supported
290-
- [x] work stealing supported
291-
- [x] sleep system call hooks supported
86+
[我有故事,你有酒吗?](https://github.com/acl-dev/open-coroutine-docs)

0 commit comments

Comments
 (0)