Example #1
0
        public static void ReleaseRefTest(SafeRefCountedHolder <object> holder)
        {
            Thread[] threads = new Thread[nThreads + 1];
            for (int i = 0; i < nThreads + 1; i++)
            {
                int threadId = i;
                threads[i] = new Thread(() =>
                {
                    holder.ReleaseRef();
                    Console.WriteLine("Thread " + threadId + " released ref current count " + holder.refCount);
                });
                threads[i].Start();
            }

            for (int i = 0; i < nThreads + 1; i++)
            {
                threads[i].Join();
            }

            Console.WriteLine("final count " + holder.refCount);
            try
            {
                holder.AddRef();
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Invalid operation after dispose");
            }
        }
Example #2
0
        public static void AddRefTest(SafeRefCountedHolder <object> holder)
        {
            Thread[] threads = new Thread[nThreads];
            for (int i = 0; i < nThreads; i++)
            {
                int threadId = i;
                threads[i] = new Thread(() =>
                {
                    holder.AddRef();
                    Console.WriteLine("Thread " + threadId + " added ref current count " + holder.refCount);
                });
                threads[i].Start();
            }

            for (int i = 0; i < nThreads; i++)
            {
                threads[i].Join();
            }

            Console.WriteLine("final count " + holder.refCount);
        }