Posts

Showing posts from 2013

Thread safe rotate index.

Sometimes you may need a rotation thread safe index. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Concurrent; using System.Threading; namespace ConsoleApplication12 { class Program { static void Main(string[] args) { Console.WriteLine("Init value = Int32.MaxValue - 10"); RotatorIndex.Init = Int32.MaxValue - 10; Thread thread1 = new Thread(new ThreadStart(ThreadMethod)); Thread thread2 = new Thread(new ThreadStart(ThreadMethod)); thread1.Start(); thread2.Start(); thread1.Join(); thread2.Join(); Console.WriteLine("Init value = - 10"); RotatorIndex.Init = - 10; thread1 = new Thread(new ThreadStart(ThreadMethod)); thread2 = new Thread(new ThreadStart(ThreadMethod)); thread1.Start(); thread2.Start(); ...