Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. class Program
  2. {
  3. static LinkedList<int> list = new LinkedList<int>();
  4. static bool[] flag = new bool[2];
  5. static int turn = 0;
  6.  
  7. static void Thread1()
  8. {
  9. for (int i = 1; i < 100; i += 2)
  10. {
  11.  
  12. //while (true)
  13. //{
  14. // flag[0] = true;
  15. // turn = 1;
  16. // while (flag[1] && turn == 1)
  17. // {
  18. // //if (turn == 1)
  19. // //{
  20. // // flag[0] = false;
  21. // // while (turn == 1)
  22. // // { }
  23. // // flag[0] = true;
  24. // //}
  25. // }
  26. list.AddLast(i);
  27. // flag[0] = false;
  28. // break;
  29. //}
  30. //list.AddLast(i);
  31. //turn = 1;
  32. }
  33. }
  34.  
  35. static void Thread2()
  36. {
  37. for (int i = 2; i < 100; i +=2)
  38. {
  39. //while (true)
  40. //{
  41. // flag[1] = true;
  42. // turn = 0;
  43. // while (flag[0] && turn == 0)
  44. // {
  45. // //if (turn == 0)
  46. // //{
  47. // // flag[1] = false;
  48. // // while (turn == 0)
  49. // // { }
  50. // // flag[1] = true;
  51. // //}
  52. // }
  53. list.AddLast(i);
  54. // flag[1] = false;
  55. // break;
  56. //}
  57. //list.AddLast(i);
  58. //turn = 0;
  59. //flag[1] = false;
  60. }
  61. }
  62. static void Main(string[] args)
  63. {
  64. flag[0] = false;
  65. flag[1] = false;
  66. LinkedListNode<int> node;
  67. Thread th1 = new Thread(Thread1);
  68. Thread th2 = new Thread(Thread2);
  69. th1.Start();
  70. th2.Start();
  71. for (node = list.First; node != null; node = node.Next)
  72. {
  73. Console.Write(node.Value + " ");
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement