public static SegmentData GetNextSegment()
        {
            lock (m_lock)
            {
                if (First == null)
                {
                    var next = new SegmentData
                    {
                        BatchId = 0,
                        Min     = 2,
                        Max     = m_batchSize
                    };
                    First = next;
                    Last  = next;
                }
                else
                {
                    var next = new SegmentData
                    {
                        BatchId = Last.BatchId + 1,
                        Min     = Last.Max,
                        Max     = Last.Max + m_batchSize
                    };
                    Last.Next = next;
                    Last      = next;
                }
            }

            return(Last);
        }
 private void FindPrimes()
 {
     while (!Stop)
     {
         var segmentData = SegmentData.GetNextSegment();
         segmentData.Primes   = CrunchPrimeSegment(segmentData.Min, segmentData.Max);
         segmentData.Complete = true;
     }
 }