Exemplo n.º 1
0
        public HashPriorityQueue <TItem /*, TStruct*/> Put(TItem t)
        {
            int queueNum = t.Priority;

            if (body[queueNum] == null)
            {
                body[queueNum] = new FIFOQueue <TItem, IQueueable <TItem> >(new QueueableLinkedList <TItem>());
            }
            body[queueNum].Put(t);
            count++;
            if (count == 1)
            {
                highestPriority = queueNum;
            }
            else
            {
                /*if (queueNum < minPriorityNum)
                 *  minPriorityNum = queueNum;*/
                if (queueNum < highestPriority)
                {
                    highestPriority = queueNum;
                }
            }
            return(this);
        }
Exemplo n.º 2
0
 static void PutThenPick(FIFOQueue queue)
 {
     for (int i = 0; i < 10000; i++)
     {
         queue.Put(i);
         queue.Pick();
     }
     Console.WriteLine("done");
 }
Exemplo n.º 3
0
 static void DequeueWhileExists(FIFOQueue queue)
 {
     while (true)
     {
         if (queue.Count() > 0)
         {
             queue.Pick();
         }
     }
 }
Exemplo n.º 4
0
        HashPriorityQueue(int priorityMax /*, TStruct structure*/)
        {
            this.priorityMax = priorityMax;
            body             = new FIFOQueue <TItem, IQueueable <TItem> > [priorityMax + 1];
            //this.FIFOQueueStructure = structure;

            /*for (int i = 0; i < priorityRange; i++)
             *  //body[i] = new FIFOQueue<TItem, TStruct>(new TStruct());
             *  body[i] = null;*/
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var queue = new FIFOQueue(10000);

            // uncomment below to observe concurrency issues even while all methods of FIFOQueue using locks inside
            //for (int i = 0; i < 10000; i++) {
            //    queue.Put(i);
            //}
            //ThreadPool.QueueUserWorkItem((o) => DequeueWhileExists(queue));
            //ThreadPool.QueueUserWorkItem((o) => DequeueWhileExists(queue));


            ThreadPool.QueueUserWorkItem((o) => PutThenPick(queue));
            ThreadPool.QueueUserWorkItem((o) => PutThenPick(queue));

            Thread.Sleep(2000);

            Console.ReadLine();
        }