Пример #1
0
        static void fun6()
        {
            UnsafeSynchronizer unsafeSynchronizer  = new UnsafeSynchronizer();
            LinkMap <int, UnsafeSynchronizer> nscd = new LinkMap <int, UnsafeSynchronizer>();

            for (int i = 0; i < 3; i++)
            {
                myk mmm = new myk();
                mmm.p = i;
                Thread t = new Thread((mmm) =>
                {
                    var m = mmm as myk;
                    //var w = o as ThreadWorkItem;
                    //if (w == null) return;
                    UnsafeSynchronizer uns = new UnsafeSynchronizer();

                    nscd.put(m.p, uns);
                    Console.WriteLine("我是线程:" + Thread.CurrentThread.Name + ":群里无聊吗?");
                    Thread.Sleep(300);
                    uns.acquire();


                    Console.WriteLine("我是线程:" + Thread.CurrentThread.Name + "退出了群聊");
                    Thread.Sleep(5000);
                    unsafeSynchronizer.release();
                });
                t.Name = "Hello,i 'am Thread: " + i;

                t.Start(mmm);
            }
            Thread.Sleep(5000);
            for (int i = 0; i < 3; i++)
            {
                nscd.get(i).release();
            }
            unsafeSynchronizer.acquire();
            Console.WriteLine("我是线程:" + Thread.CurrentThread.Name + "群主解散了群聊");
            //threads[0].Suspend();
        }
Пример #2
0
 //这叫享元模式吗?
 public O getController <O>()
 {
     return((O)proxyObjectMap.get(typeof(O).Name));
 }