Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>You can do it with C++ coroutines, but it's much harder to do correctly than in Rust if you want to maintain any sense of conviction that the system is correct.

Could you elaborate on this?



C++ just lets you pass a reference or pointer from one task's stack to another task or thread, with no assurance that the callee task terminates before the caller's stack is deallocated (i.e. the caller returns before its children terminate).

This is a compile error in Rust, and you need unsafe code to achieve it. But then the real power is that you can construct a safe API that lets you do it safely, fully checked at compile time.

See `std::thread::scope` in the standard library, or `rayon::scope` if you want an implementation based on thread pools.


Thanks!

>See `std::thread::scope` in the standard library, or `rayon::scope` if you want an implementation based on thread pools.

These seem to be about multu-threaded code if I got it right, but how does async work?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: