I’m glad to release MAY 0.2.0. You can ref the Changes in github.
ChangeLog
v0.2.0
MAY 0.2.0 focus on changing the spawn APIs to unsafe so that apply rust safety rules. And this is a breaking change to v0.1.0
- all the
spawnAPs are declared withunsafeforTLSaccess and stack exceed limitations - add
go!macro for ease of use ‘spawn’ APIs to avoid writingunsafeblock explicitly - add simple http server example
- remove
unsafecode forMAYconfiguration - improve documentation
Why spawn a coroutine is unsafe
you can ref the caveat of May for the following two reasons.
- if user access
TLS, it may trigger undefined behavior - if user coroutine implementation exceed the stack limitation, it will trigger undefined behavior.
To apply rust safety rules, the spawn APIs must be declared with unsafe keyword.
The go! macro
Because of the unsafe property of spawn APIs, now you have to add a unsafe block when creating a new coroutine, like this:
1 | unsafe { |
However, surround everything in the unsafe block has two drawbacks.
- you can’t get enough optimization by the rust compiler for the
unsafeblock - it’s a little annoying to write the
unsafeevery where.
a better code should be like this to enable the optimization for the coroutine implementation:
1 | let closure = move || { |
So I introduce the go! macro just doing the same thing for you. It’s just a thin wrapper for the spawn APIs.1
let join_handle = go!(move || { ... });