Posts

Showing posts from 2014

Asynchronous Programming Concepts (.NET related)

Async execution - It's all about responsiveness. Old code scenarios To use WaitHandle from a Task. Implement the APM pattern by FromAsync methods and "Tasks Forest" Implement the EPM pattern by TaskCompletionSource. Asynchronous Task means the Threadless Task. Asynchronous Tasks may have only the next statuses: Fault, RunToCompletion, Cancelled. Continuation for Asynchronous Tasks Use the TaskCompletionSource<T> class. async await A syntactic sugar for awful amount of work. A compiler's underground job. A enumeration, try, finally, using and etc. Users SynchronizationContext implicitly. Unwrap multiple exceptions The await will return only the first exception from a AggregateException. There is a useful trick to unwrap multiple exceptions. await task.ContinueWith(     ( ) => { } ,     TaskContinuationOptions. ExecuteSynchronously ); var results = task .Result; Multiple await Preventing of lost exceptions with multiple

Concurrent Programming

Asynchronous Programming Parallel Programming Multithreaded Programming

Parallel Programming Concepts (.NET related)

Parallel execution - It's all about loaded computations. Common Types of Parallelism Data     amount of data processed by one operation in parallel. Patterns     Parallel Loops Implementations     Parallel.Foreach     Parallel.For Task     Some data or amount of data processed by many operations. Patterns     Parallel tasks Implementations     Parallel.Invoke Dataflow     Operations processed in some flow or order. Patterns     Features     Pipeline Embarrassingly parallel     computations entirely independent of one another. No dataflow in between the options. Patterns Parallel Loops Parallel.For / Parallel.Foreach Parallel Tasks Parallel.Invoke Parallel Aggregation Map- Reduce Producer-Consumer By Parallel Loops with TLS (Task Local Storage) parameter or by Wait All One By One Futures Dynamic Task Parallelism Pipelines + Concurrent Data Structures. Dataflow (many to one + one to many, ContinueWhen All ) +Concurrent Data Structures.

Multithreaded Programming

Synchronization primitives Semaphore Slim

Wait Many

IAsyncResult needs to be closed.

Hashing for collection's keys

Key objects must be immutable as long as they are used as keys in the Hashtable. When an element is added to the Hashtable, the element is placed into a bucket based on the hash code of the key. Subsequent lookups of the key use the hash code of the key to search in only one particular bucket, thus substantially reducing the number of key comparisons required to find an element. GetBucket(item. GetHashCode ()) Any object that creates a hashvalue should change the hashvalue, when the object changes, but it must not - absolutely must not - allow any changes to itself, when it is used inside a Hashtable (or any other Hash-using object, of course). So, just make GetHashCode result change, when the object data changes, and if the use of the object inside of hash using lists or objects is intended (or just possible) then make the object either immutable or create a readonly flag to use for the lifetime of a hashed list containing the object. (By the way: All of this is not C# oder

Choosing Collections in .NET Framework

(In progress...) Big O Notation     http://stackoverflow.com/questions/2307283/what-does-olog-n-mean-exactly . The Generic Collections: System.Collections.Generic namespace     Associative Collection Classes (stores a value by a key, associates the value with the key)         useful to lookup/manipulate a collection using a key value         The Dictionary<TKey,TValue>             Best for high performance lookups.                 is the fastest class for associative lookups/inserts/deletes because it uses a hash table under the covers                 The speed of retrieval depends on the quality of the hashing algorithm of the type specified for TKey.                 the key type should correctly implement GetHashCode() and Equals() appropriately                 or you should provide an external IEqualityComparer to the dictionary on construction.                 O(1)                     insert/delete/lookup time of items in the dictionary is amortized constant ti