Parallel and The C# Memory Model

Wednesday, March 6, 2013

Parallel and The C# Memory Model Parallel programming can be tricky, both compiler and CPU's optimization can lead into a twilight zone's debugging. lets take the following code snippet snippet: Code Snippet class Program {     static void Main(string args)     {         Console.WriteLine("Start");         var u = new Util();         u.Exec();         Console.ReadKey();     } }   public class Util {     private bool _stop = true;     public void Exec()     {         Task t = Task.Run(() =>             {                 bool b = true;                 while (_stop)                 {                     b = !b;                 }                 Console.WriteLine("Complete {0}", b);             });         Thread.Sleep(30);         _stop = false;     } } ...

Rx – DistinctUntilChanged

Thursday, February 2, 2012

Rx - DistinctUntilChanged this post will focus on the simple yet very useful DistinctUntilChanged operator. sometimes a datum stream may produce the same value for a while, you can see it in stock exchange stream the value of specific stock may be steady for a while. the observer can reduce its computation level by ignoring a repeatable value (sequential repeatable value, for none sequential you can use the Distinct operator). the DistinctUntilChanged is having the following overloads: Code Snippet IObservable<TSource> DistinctUntilChanged<TSource>(); IObservable<TSource> DistinctUntilChanged<TSource, TKey>(     Func<TSource, TKey> keySelector); IObservable<TSource>...