4 ms·
They're not really the same: you know that an async function may potentially suspend and have other code run before its completion, while a normal function (in
by nostrademons 6y ago
They're not really the same: you know that an async function may potentially suspend and have other code run before its completion, while a normal function (in the absence of threads and signals) is guaranteed to run atomically, at least as far as your process's memory space is concerned. You also know that the only points at which an async function may suspend are an 'await' statement, and so data invariants that don't cross await statements or other async function calls can be reasoned about as if you had purely sequential code.
That's precisely the coloring that makes async useful. Without it you need to explicitly protect all shared data with mutexes or other synchronization primitives. 40+ years of threaded programming has shown that programmers cannot generally be trusted to get this right, and this in an area ripe with bugs.
- sanxiyn 6y agoProgrammers cannot get threading right, but Rust can.
- johnnycerberus 6y agoRust won't magically make your threaded code blocks right. It can just provide you tools to ensure that memory won't leak. It's just 1/10 of the solution.
- sanxiyn 6y agoRust solves threading-specific problems. Yes it's partial, but other problems happen in both threaded code and async code, so that's not a reason to choose one over another.
- steveklabnik 6y agoRust does not ensure that your code is free of memory leaks, to be clear.