Esempio n. 1
0
        public static void Test()
        {
            SafeList <string> list = new SafeList <string>();

            Thread tr1 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunReader));
            Thread tr2 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunReader));
            Thread tr3 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunReader));
            Thread tr4 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunReader));
            Thread tr5 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunReader));
            Thread tr6 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunReader));

            Thread tw1 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunWriter));
            Thread tw2 = new Thread(new ThreadStart(new ReadWriteSimulation(list).RunWriter));

            tr1.Start();
            tr2.Start();
            tr3.Start();
            tr4.Start();
            tr5.Start();
            tr6.Start();

            tw1.Start();
            tw2.Start();

            tr1.Join();
            tr2.Join();
            tr3.Join();
            tr4.Join();
            tr5.Join();
            tr6.Join();

            tw1.Join();
            tw2.Join();

            foreach (string item in list.GetList())
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 2
0
 public ReadWriteSimulation(SafeList <string> output)
 {
     this.output = output;
 }