home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Threading;
- using System.Runtime.Remoting;
-
-
- //[Synchronization()]
- //[Synchronization(int flag, bool reEntrant)]
- //[Synchronization(int flag)]
- //[Synchronization(bool reEntrant)]
-
- //[Synchronization(Synchronization.NOT_SUPPORTED)]
- //[Synchronization(Synchronization.SUPPORTED)]
- //[Synchronization(Synchronization.REQUIRED)]
- //[Synchronization(Synchronization.REQUIRES_NEW)]
-
- [Synchronization()]
- public class Foo : ContextBoundObject
- {
- int count=0;
-
- public Foo()
- {
- Console.WriteLine("Hash : {0} Foo()", Thread.CurrentThread.GetHashCode());
- }
-
- public void Method1()
- {
- int localCount = count;
- localCount++;
- count = localCount;
- Console.WriteLine("Hash : {0} Foo.Method1 : count : {1}", Thread.CurrentThread.GetHashCode(), localCount);
- }
- }
-
- //[ThreadAffinity(ThreadAffinity.NOT_SUPPORTED)]
- //[ThreadAffinity(ThreadAffinity.SUPPORTED)]
- //[ThreadAffinity(ThreadAffinity.REQUIRED)]
- //[ThreadAffinity(ThreadAffinity.REQUIRES_NEW)]
-
- [ThreadAffinity()]
- public class Baz : ContextBoundObject
- {
- int count=0;
-
- public Baz()
- {
- Console.WriteLine("Hash : {0} Baz()", Thread.CurrentThread.GetHashCode());
- }
-
- public void Method1()
- {
- int localCount = count;
- localCount++;
- count = localCount;
-
- Console.WriteLine("Hash : {0} Baz.Method1 : count : {1}", Thread.CurrentThread.GetHashCode(), localCount);
- }
- }
-
- public class Simple
- {
- public static Foo foo;
- public static Baz baz;
-
- public static void ThreadMethod()
- {
- for (int j=0; j < 5; j++)
- {
- foo.Method1();
- }
-
- for (int k=0; k < 5; k++)
- {
- baz.Method1();
- }
-
-
- }
-
- public static int Main(String[] args)
- {
- Console.WriteLine("Hash : {0} Main", Thread.CurrentThread.GetHashCode());
-
- foo = new Foo();
- foo.Method1();
-
- baz = new Baz();
- baz.Method1();
-
- for (int i=0;i < 5; i++)
- {
- ThreadStart ts = new ThreadStart(ThreadMethod);
- Thread t = new Thread(ts);
- t.Start();
- }
-
- return 0;
- }
- }
-