Click here to Skip to main content
15,881,172 members
Articles / General Programming / Threads

Smart Thread Pool

Rate me:
Please Sign up or sign in to vote.
4.96/5 (314 votes)
27 Aug 2012Ms-PL40 min read 2.2M   29.1K   1.1K  
A .NET Thread Pool fully implemented in C# with many features.
using System;

using NUnit.Framework;

using Amib.Threading;
using Amib.Threading.Internal;

using SmartThreadPoolTests;

namespace PriorityQueueTests
{
	/// <summary>
	/// Summary description for TestWorkItemsQueue.
	/// </summary>
	[TestFixture]
	[Category("TestWorkItemsQueue")]
	public class TestWorkItemsQueue
	{
		public TestWorkItemsQueue()
		{
		}
	
		[Test]
		public void Init()
		{
		}

		[Test]
		public void IdempotenceWaiterEntry()
		{
			WorkItemsQueue q = new WorkItemsQueue();

			Assert.AreEqual(0, q.WaitersCount);

			WorkItemsQueue.WaiterEntry we1 = new Amib.Threading.Internal.WorkItemsQueue.WaiterEntry();
			q.PushWaiter(we1);

			Assert.AreEqual(1, q.WaitersCount);

			q.PushWaiter(we1);	
	
			Assert.AreEqual(1, q.WaitersCount);

			WorkItemsQueue.WaiterEntry we2 = new Amib.Threading.Internal.WorkItemsQueue.WaiterEntry();
			q.PushWaiter(we2);	

			Assert.AreEqual(2, q.WaitersCount);

			q.PushWaiter(we2);	

			Assert.AreEqual(2, q.WaitersCount);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior)
Israel Israel
B.Sc. in Computer Science.
Works as Software Developer.

Comments and Discussions