4 ms·
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 call
by simonask 2mo ago
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.
- drysine 2mo agoThanks! >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?