Release May 0.2.0

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 spawn APs are declared with unsafe for TLS access and stack exceed limitations
  • add go! macro for ease of use ‘spawn’ APIs to avoid writing unsafe block explicitly
  • add simple http server example
  • remove unsafe code for MAY configuration
  • improve documentation

Why spawn a coroutine is unsafe

you can ref the caveat of May for the following two reasons.

  1. if user access TLS, it may trigger undefined behavior
  2. 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
2
3
4
5
unsafe {
may::coroutine::spawn(|| {
...
});
}

However, surround everything in the unsafe block has two drawbacks.

  1. you can’t get enough optimization by the rust compiler for the unsafe block
  2. it’s a little annoying to write the unsafe every where.

a better code should be like this to enable the optimization for the coroutine implementation:

1
2
3
4
5
6
7
let closure = move || {
...
};

unsafe {
may::coroutine::spawn(closure);
}

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 || { ... });

Happy new year for 2018!