コード例 #1
0
ファイル: SharedData.cs プロジェクト: ehershey/development
 public static SharedData GetInstance()
 {
     lock(SharedDataLock)
     {
         Console.WriteLine("ENTER SharedData.GetInstance() is executing in thread(" + Thread.CurrentThread.GetHashCode() + ")" );
         if (m_instance == null)
         {
             Console.WriteLine("m_instance created!");
             m_instance = new SharedData();
         }
         Console.WriteLine("Exit SharedData.GetInstance() is executing in thread(" + Thread.CurrentThread.GetHashCode() + ")" );
     }
     return m_instance;
 }
コード例 #2
0
ファイル: SimpleThread.cs プロジェクト: ehershey/development
        public void run()
        {
            m_threadenabled = true;
            m_sd_instance = SharedData.GetInstance();
            Thread.Sleep(200);

            while(m_threadenabled)
            {
                m_loopcnt++;
                Console.WriteLine("thread " + m_name + " executing loop#" + m_loopcnt);            
                //bad!
    //            int x = SharedData.GetInstance().GetNum();
    //            x++;
    //            SharedData.GetInstance().SetNum(x);
    //            SharedData.GetInstance().incNum();
                m_sd_instance.incNum();            
                //end bad!!
            }
            Console.WriteLine(m_name + "exiting..");
            m_thread_complete = true;
        }