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;
- using System.Threading.Tasks;
- namespace ConsoleApp13
- {
- class Program
- {
- static void Main(string[] args)
- {
- Calendar c1 = Calendar.getInstance();
- Calendar c2 = Calendar.getInstance();
- Thread[] threads = new Thread[500];
- for(int i = 0; i < threads.Length; i++)
- {
- threads[i] = new Thread(createInstance);
- threads[i].Start();
- }
- Console.WriteLine(c1 == c2);
- Console.WriteLine(c1.Equals(c2));
- Console.ReadKey();
- }
- private static void createInstance()
- {
- Calendar c = Calendar.getInstance();
- }
- }
- class Calendar
- {
- private static Calendar instance = null;
- private Calendar()
- {
- }
- public static Calendar getInstance()
- {
- Thread.Sleep(new Random().Next(0, 1000));
- if(null == instance)
- {
- instance = new Calendar();
- Console.WriteLine("new Calendar();");
- }
- return instance;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement