Advertisement
Guest User

volatile

a guest
Mar 22nd, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7. namespace VolatileTest
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             Test.TestVolatile();
  14.         }
  15.     }
  16.  
  17.     class Test
  18.     {
  19.         int foo;
  20.  
  21.         public static void TestVolatile()
  22.         {
  23.             var test = new Test();
  24.  
  25.             new Thread(delegate() { Thread.Sleep(500); test.foo = 255; }).Start();
  26.  
  27.             while (test.foo != 255) ;
  28.             Console.WriteLine("OK");
  29.         }
  30.     }
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement