コード例 #1
0
ファイル: exercicio-3.cs プロジェクト: tiagoaguiar100/PADI
 public void AssyncInvoke(ThrWork action)
 {
     if (buffer.Count != 0 && buffer.Capacity == buffer.Count)
     {
         buffer.RemoveAt(0);
     }
     buffer.Add(action);
 }
コード例 #2
0
ファイル: ThreadPool.cs プロジェクト: vsnunes/dad1819
 public void consomeExec()
 {
     while (true)
     {
         ThrWork tw = buf.Consume();
         tw();
     }
 }
コード例 #3
0
 public void consomeExec()
 {
     while (true)
     {
         // instantiate delegate
         ThrWork tw = buf.Consume();
         getPermission();
         // call the delegate
         tw();
     }
 }
コード例 #4
0
    public static void Main()
    {
        ThrPool tpool = new ThrPool(5, 10);
        ThrWork work  = null;

        for (int i = 0; i < 5; i++)
        {
            A a = new A(i);
            tpool.AssyncInvoke(new ThrWork(a.DoWorkA));
            B b = new B(i);
            tpool.AssyncInvoke(new ThrWork(b.DoWorkB));
        }
        Console.ReadLine();
    }
コード例 #5
0
    public void AssyncInvoke(ThrWork action)
    {
        lock (this)
        {
            while (bufIndex == buffer.Length)
            {
                Monitor.Wait(this);
            }

            buffer[bufIndex] = action;
            bufIndex++;
            Monitor.PulseAll(this);
        }
    }
コード例 #6
0
        public void AssyncInvoke(ThrWork action)
        {
            int new_index = (this.write_index + 1) % this.bufSize;

            Monitor.Enter(this.request_queue);
            Thread.Sleep(10);
            if (this.request_queue[new_index] != null)
            {
                Monitor.Exit(this.request_queue);
                return;
            }
            this.write_index = new_index;
            this.request_queue[new_index] = action;
            Monitor.Exit(this.request_queue);
        }
コード例 #7
0
ファイル: exercicio-3.cs プロジェクト: tiagoaguiar100/PADI
 private void DoWork()
 {
     while (true)
     {
         Monitor.Enter(this);
         if (buffer.Count > 0)
         {
             ThrWork work = (ThrWork)buffer[0];
             buffer.RemoveAt(0);
             Monitor.Exit(this);
             work();
         }
         else
         {
             Monitor.Exit(this);
         }
     }
 }
コード例 #8
0
 /** Equivalent to an enqueue */
 public void WriteRequest(ThrWork request)
 {
     lock (_requestsQueue)
     {
         // No space for more requests, wait until a request is processed
         while (_requestsQueue.Count >= _maxSize)
         {
             Console.WriteLine("Write - Thread {0} is sleeping", Thread.CurrentThread.ManagedThreadId);
             Monitor.Wait(_requestsQueue);
         }
         Console.WriteLine("Write - Thread {0} is writing", Thread.CurrentThread.ManagedThreadId);
         _requestsQueue.Enqueue(request);
         if (_requestsQueue.Count == 1)
         {
             // wake up some blocked thread to come process request
             Monitor.PulseAll(_requestsQueue); // needs to have pulseAll!
         }
     }
 }
コード例 #9
0
        /** Equivalent to a dequeue */
        public ThrWork ReadRequest()
        {
            lock (_requestsQueue)
            {
                // No requests to read, wait until a new request goes into the queue
                while (_requestsQueue.Count == 0)
                {
                    Console.WriteLine("Read - Thread {0} is sleeping", Thread.CurrentThread.ManagedThreadId);
                    Monitor.Wait(_requestsQueue);
                }
                Console.WriteLine("Read - Thread {0} is reading", Thread.CurrentThread.ManagedThreadId);
                ThrWork request = _requestsQueue.Dequeue();
                if (_requestsQueue.Count == _maxSize - 1)
                {
                    // wake up some blocked thread to come write a new request
                    Monitor.PulseAll(_requestsQueue); // needs to have pulseAll!
                }

                return(request);
            }
        }
コード例 #10
0
    private void threadLoop()
    {
        while (true)
        {
            lock (queue) {
                while (queue.Count == 0) //waiting for work
                {
                    System.Console.WriteLine("(queue.Count == 0)");
                    Monitor.Wait(queue);
                }

                ThrWork work = queue.Dequeue();

                if (queue.Count == queueCapacity - 1) //a produced is waiting for a free space
                {
                    Monitor.Pulse(queue);
                }
                work();
            }
        }
    }
コード例 #11
0
    public void Execute()
    {
        while (!end)
        {
            lock (this)
            {
                while (bufIndex == 0 || thrIndex == pool.Length)
                {
                    Monitor.Wait(this);
                }

                bufIndex--;
                ThrWork ex = (ThrWork)buffer[bufIndex];
                thrIndex++;
                ex();
                thrIndex--;

                Monitor.PulseAll(this);
            }
        }
    }
コード例 #12
0
    public void AssyncInvoke(ThrWork action)
    {
        lock (queue)
        {
            while (queueCapacity == queue.Count)
            {
                System.Console.WriteLine("(queueCapacity == queue.Count)" + queue.Count);

                Monitor.Wait(queue);
            }

            queue.Enqueue(action);

            //every thread is waiting
            if (queue.Count == 1)
            {
                //so notify only one thread that is able to work
                Monitor.Pulse(queue);
            }
        }
    }
コード例 #13
0
 public void AssyncInvoke2(ThrWork action)
 {
     //Thread t = new Thread(this.AssyncInvoke);
     //t.Start(action);
 }
コード例 #14
0
 public void AssyncInvoke(ThrWork action)
 {
     Monitor.Enter(this);
     while (buffer.Count != 0 && buffer.Capacity == buffer.Count)
     {
         Monitor.Wait(this);
         //buffer.RemoveAt(0);
     }
     buffer.Add(action);
     if (buffer.Count == 1) Monitor.Pulse(this);
     Monitor.Exit(this);
 }
コード例 #15
0
ファイル: Server.cs プロジェクト: vsnunes/dad1819
 public Server()
 {
     tupleSpace = new TupleSpaceSMR();
     tpool      = new ThreadPool(5, 10);
     work       = null;
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: bphenriques/PADI-2015
 public void AssyncInvoke2(ThrWork action)
 {
     //Thread t = new Thread(this.AssyncInvoke);
     //t.Start(action);
 }
コード例 #17
0
 public void AssyncInvoke(ThrWork action)
 {
     // TODO
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: bphenriques/PADI-2015
    public void AssyncInvoke(ThrWork action)
    {
        lock (queue)
        {
            while (queueCapacity == queue.Count)
            {
                System.Console.WriteLine("(queueCapacity == queue.Count)" + queue.Count);

                Monitor.Wait(queue);
            }

            queue.Enqueue(action);

            //every thread is waiting
            if (queue.Count == 1)
            {
                //so notify only one thread that is able to work
                Monitor.Pulse(queue);
            }
        }
    }
コード例 #19
0
ファイル: Program.cs プロジェクト: danielaLopes/PADI
 /*
  * Method for asynchronous execution of the delegate ThrWork.
  * Writes requests into the request queue.
  */
 public void AssyncInvoke(ThrWork action)
 {
     _requestsQueue.WriteRequest(action);
 }
コード例 #20
0
ファイル: ThreadPool.cs プロジェクト: vsnunes/dad1819
 public void AssyncInvoke(ThrWork action)
 {
     buf.Produce(action);
     Console.Write("Request Started");
 }
コード例 #21
0
 public void AssyncInvoke(ThrWork action)
 {
     buf.Produce(action);
 }
コード例 #22
0
        public void AssyncInvoke(ThrWork action)
        {
            buf.Produce(action);

            Console.WriteLine("Submitted action");
        }
コード例 #23
0
ファイル: exercicio-3.cs プロジェクト: jfloff/PADI
 public void AssyncInvoke(ThrWork action)
 {
     if (buffer.Count != 0 && buffer.Capacity == buffer.Count)
     {
         buffer.RemoveAt(0);
     }
     buffer.Add(action);
 }
コード例 #24
0
ファイル: Program.cs プロジェクト: botelhorui/DAD
 public void AssyncInvoke(ThrWork action)
 {
     lock (tasks)
     {
         if (tasks.Count < bufSize)
         {
             tasks.Enqueue(action);
             Monitor.Pulse(tasks);
             //sem.Release();
         }
         else
         {
             ; // buffer is full, discard action
         }
     }
 }