Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7.  
  8. namespace ConsoleApplication2
  9. {
  10. class Program
  11. {
  12. static public Mutex mtx = new Mutex();
  13. //Doubly_Linked_List a = new Doubly_Linked_List();
  14. static List<int> lst = new List<int>();
  15.  
  16. static void Main(string[] args)
  17. {
  18. //Console.ReadKey();
  19.  
  20. Thread q = new Thread(f1);
  21. Thread w = new Thread(f2);
  22. q.Start();
  23. w.Start();
  24. q.Join();
  25. w.Join();
  26. Thread r = new Thread(show);
  27. r.Start();
  28.  
  29. Console.ReadKey();
  30. }
  31.  
  32. static private void show()
  33. {
  34. foreach(int itm in lst)
  35. {
  36. Console.WriteLine(itm);
  37. }
  38. }
  39.  
  40. static private void f1()
  41. {
  42.  
  43. for (int i = 1; i < 100; i += 2)
  44. {
  45. Thread.Sleep(50);
  46. mtx.WaitOne();
  47. //a.Push_Back(Convert.ToString(i));
  48. lst.Add(i);
  49. mtx.ReleaseMutex();
  50. }
  51.  
  52. }
  53.  
  54. static private void f2()
  55. {
  56. for (int i = 2; i < 100; i += 2)
  57. {
  58. Thread.Sleep(50);
  59. mtx.WaitOne();
  60. //a.Push_Back(Convert.ToString(i));
  61. lst.Add(i);
  62. mtx.ReleaseMutex();
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement