Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static LinkedList<int> list = new LinkedList<int>();
- static bool[] flag = new bool[2];
- static int turn = 0;
- static void Thread1()
- {
- for (int i = 1; i < 100; i += 2)
- {
- //while (true)
- //{
- // flag[0] = true;
- // turn = 1;
- // while (flag[1] && turn == 1)
- // {
- // //if (turn == 1)
- // //{
- // // flag[0] = false;
- // // while (turn == 1)
- // // { }
- // // flag[0] = true;
- // //}
- // }
- list.AddLast(i);
- // flag[0] = false;
- // break;
- //}
- //list.AddLast(i);
- //turn = 1;
- }
- }
- static void Thread2()
- {
- for (int i = 2; i < 100; i +=2)
- {
- //while (true)
- //{
- // flag[1] = true;
- // turn = 0;
- // while (flag[0] && turn == 0)
- // {
- // //if (turn == 0)
- // //{
- // // flag[1] = false;
- // // while (turn == 0)
- // // { }
- // // flag[1] = true;
- // //}
- // }
- list.AddLast(i);
- // flag[1] = false;
- // break;
- //}
- //list.AddLast(i);
- //turn = 0;
- //flag[1] = false;
- }
- }
- static void Main(string[] args)
- {
- flag[0] = false;
- flag[1] = false;
- LinkedListNode<int> node;
- Thread th1 = new Thread(Thread1);
- Thread th2 = new Thread(Thread2);
- th1.Start();
- th2.Start();
- for (node = list.First; node != null; node = node.Next)
- {
- Console.Write(node.Value + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement