Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- namespace ConsoleApplication2
- {
- class Program
- {
- static public Mutex mtx = new Mutex();
- //Doubly_Linked_List a = new Doubly_Linked_List();
- static List<int> lst = new List<int>();
- static void Main(string[] args)
- {
- //Console.ReadKey();
- Thread q = new Thread(f1);
- Thread w = new Thread(f2);
- q.Start();
- w.Start();
- q.Join();
- w.Join();
- Thread r = new Thread(show);
- r.Start();
- Console.ReadKey();
- }
- static private void show()
- {
- foreach(int itm in lst)
- {
- Console.WriteLine(itm);
- }
- }
- static private void f1()
- {
- for (int i = 1; i < 100; i += 2)
- {
- Thread.Sleep(50);
- mtx.WaitOne();
- //a.Push_Back(Convert.ToString(i));
- lst.Add(i);
- mtx.ReleaseMutex();
- }
- }
- static private void f2()
- {
- for (int i = 2; i < 100; i += 2)
- {
- Thread.Sleep(50);
- mtx.WaitOne();
- //a.Push_Back(Convert.ToString(i));
- lst.Add(i);
- mtx.ReleaseMutex();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement