News for hackers. Stuff that matters.
Re:Scipio: A Thread-per-Core Crate for Rust and Linux by Joker_vD on Tuesday November 03, 2020 @09:07AM (#24979741)
I don't know too much about Rust, but in .NET, blocking on Task.Result is considered an anti-pattern and a Bad Thing To Do. Not in the least because it very easily leads to deadlocks.
Re:Scipio: A Thread-per-Core Crate for Rust and Linux by davidhyde on Tuesday November 03, 2020 @09:56AM (#24980134)
This is considered bad in .NET because callbacks can "Post" back to the original SynchronizationContext which depends on what async/await is being used for. For example, a call to await on a WPF UI thread will join to the calling thread so if you call Task.Result without configuring the task to not join back to the calling thread then you can deadlock the callback processing queue. To avoid this you would use ConfigureAwait(false) depending on your situation. It's the source of a lot of confusion in .NET. I don't believe that Rust has this "feature" and if you somehow wrote code to achieve the same thing as .NET does then it probably wouldn't compile in Rust due to the ownership rules.

Source: https://devblogs.microsoft.com/dotnet/configureawait-faq/

Re:Scipio: A Thread-per-Core Crate for Rust and Linux by Joker_vD on Tuesday November 03, 2020 @10:36AM (#24980559)
Wait, Rust doesn't associate executors with futures? If it does, and there is a single-threaded executor available, then it's absolutely possible to deadlock just like in .NET.
Re:Scipio: A Thread-per-Core Crate for Rust and Linux by davidhyde on Tuesday November 03, 2020 @02:23PM (#24982986)
That is a good question. It is possible to avoid deadlocks in a single threaded executor with higher priority interrupts but I’m no authority in this area. Maybe someone else can comment. Most of my understanding in this area comes from reading this article: https://os.phil-opp.com/async-await/
Re:Scipio: A Thread-per-Core Crate for Rust and Linux by Matthias247 on Wednesday November 04, 2020 @12:12AM (#24986559)
In Rust a task which is started on a given executor never leaves it. It can not switch executors like it can in C# where the continuations could be called on an arbitrary thread. In Rust, wakeups for an async task essentially just schedule it for running again, but the execution happens on the previous executor.

Anyway, in both models you can have deadlocks. And even if there is no deadlock, blocking the eventloop is still an antipattern, since it prevents other tasks which might be able to make progress from running.

Re:Scipio: A Thread-per-Core Crate for Rust and Linux by Diggsey on Thursday November 05, 2020 @08:02AM (#24997859)
`block_on` does not block the calling thread: it runs the closure on a separate thread-pool based executor designed for CPU-bound tasks.

The calling thread immediately yields until the blocking work task completes and wakes it up again.