Asynchrony

Concurrency in c# cookbook by Steven Donald. Joe Duffy - 15 Years of Concurrency. In a Tale of Three Safeties, we discussed three kinds of safety: type, memory, and concurrency.

In this follow-on article, we will dive deeper into the last, and perhaps the most novel yet difficult, one. Concurrency-safety led me to the Midori project in the first place, having spent years on .NET and C++ concurrency models leading up to joining. We built some great things that I’m very proud of during this time. Perhaps more broadly interesting, however, are the reflections on this experience after a few years away from the project. I’ve tried to write this article about 6 times since earlier this year, and I’m thrilled to finally share it.

Parallel Programming with .NET. A few years back, Wes Dyer wrote a great post on monads, and more recently, Eric Lippert wrote a terrific blog series exploring monads and C#.

In that series, Eric alluded to Task<TResult> several times, so I thought I’d share a few related thoughts on Task<TResult> and the async/await keywords.
Await anything; - .NET Parallel Programming. One of the very cool things about the new await keyword in C# and Visual Basic is that it’s pattern based.

It works great with Task and Task<TResult>, and awaiting those two types will represent the vast majority of uses, but they’re by no means the only types that can be awaited. The languages support awaiting any instance that exposes the right method (either instance method or extension method): GetAwaiter. A GetAwaiter needs to implement the INotifyCompletion interface (and optionally the ICriticalNotifyCompletion interface) and return a type that itself exposes three members: bool IsCompleted { get; }void OnCompleted(Action continuation);TResult GetResult(); // TResult can also be void. Techdays 2014 the Netherlands. Julian m bucknall >> Lock-free data structures: the queue.

Multithreading - Lockfree standard collections and tutorial or articles. Concurrency: What Every Dev Must Know About Multithreaded Apps. Concurrency What Every Dev Must Know About Multithreaded Apps Vance Morrison Ten years ago only hard-core systems programmers worried about the intricacies of writing correct code in the presence of more than one thread of execution. Most programmers stuck with sequential programs to avoid the problem altogether. Now, however, multiprocessor machines are becoming commonplace. Unfortunately, writing correct, multithreaded programs is not easy. I have three goals in this article. Threads and Memory At its heart, multithreaded programming seems simple enough. Figure 3 Shared Memory Threading Model The most commonly deployed multithreaded communication model is called the shared memory model.

Understanding Low-Lock Techniques in Multithreaded Apps. Lock-free programming is a challenge, not just because of the complexity of the task itself, but because of how difficult it can be to penetrate the subject in the first place.

Since then, a lot of good material has been written, ranging from abstract theory and proofs of correctness to practical examples and hardware details. I’ll leave a list of references in the footnotes. At times, the information in one source may appear orthogonal to other sources: For instance, some material assumes sequential consistency, and thus sidesteps the memory ordering issues which typically plague lock-free C/C++ code. The new C++11 atomic library standard throws another wrench into the works, challenging the way many of us express lock-free algorithms.
Processing Sequences of Asynchronous Operations with Tasks - .NET Parallel Programming.

Of late, I’ve seen multiple folks asking about how to use tasks to asynchronously execute a sequence of operations.

The entire purpose of ConfigureAwait() is to allow you to control what happens when you use await on a Task. As such, there's no need to return a new Task - it only needs to return something that's awaitable. Wrapping this into a new Task would add quite a bit of overhead, as well as confuse the issue, as it'd imply that you'd use it as a Task as well as just calling await on it. By returning a new struct instead (ConfiguredTaskAwaitable) which follows the guidelines to work with await, the compiler keeps the overhead lower and the usage more clear.
ExecutionContext vs SynchronizationContext - .NET Parallel Programming. Asynchronous Programming - Async Performance: Understanding the Costs of Async and Await.

Asynchronous programming has long been the realm of only the most skilled and masochistic of developers—those with the time, inclination and mental capacity to reason about callback after callback of non-linear control flow.

With the Microsoft .NET Framework 4.5, C# and Visual Basic deliver asynchronicity for the rest of us, such that mere mortals can write asynchronous methods almost as easily as writing synchronous methods. No more callbacks. No more explicit marshaling of code from one synchronization context to another. No more worrying about the flowing of results or exceptions.

No more tricks that contort existing language features to ease async development.
Avoiding And Detecting Deadlocks In .NET Apps with C# and C++
No More Hangs Advanced Techniques To Avoid And Detect Deadlocks In .NET Apps.