public ThreadPool() { m_workers = new BlockingFixedQueue <Thread>(MaxThreads); for (var i = 0; i < MaxThreads; ++i) { var worker = new Thread(Worker) { Name = string.Concat("Worker ", i) }; worker.Start(); m_workers.Enqueue(worker); } }
private void initializePlan() { // getting avalible memory m_threadBouncer = new AutoResetEvent(false); var availablePhysicalMemory = new ComputerInfo().AvailablePhysicalMemory; var clrMemoryRestriction = 1UL << 31; // 2gb var avalibleMemory = Math.Min(availablePhysicalMemory, clrMemoryRestriction); // 0.9 here is a synthetic restriction for case when avalible physical memory is less then net restriction var appAvalibleMemory = (ulong)(0.9 * avalibleMemory); var blockCountOnTwoQueues = (int)appAvalibleMemory / c_blockSize; // trying 50-50 var rawQueueSize = blockCountOnTwoQueues / 2; var compressedQueueSize = blockCountOnTwoQueues / 2; if (compressedQueueSize == 0 || rawQueueSize == 0) { throw new InsufficientMemoryException("Not enough memory"); } m_rawBlockQueue = new BlockingFixedQueue <FilePart>(rawQueueSize); m_processedBlockQueue = new BlockingFixedSortQueue <FilePart>(compressedQueueSize); }