public void AssyncInvoke(ThrWork action) { if (buffer.Count != 0 && buffer.Capacity == buffer.Count) { buffer.RemoveAt(0); } buffer.Add(action); }
public void consomeExec() { while (true) { ThrWork tw = buf.Consume(); tw(); } }
public void consomeExec() { while (true) { // instantiate delegate ThrWork tw = buf.Consume(); getPermission(); // call the delegate tw(); } }
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(); }
public void AssyncInvoke(ThrWork action) { lock (this) { while (bufIndex == buffer.Length) { Monitor.Wait(this); } buffer[bufIndex] = action; bufIndex++; Monitor.PulseAll(this); } }
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); }
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); } } }
/** 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! } } }
/** 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); } }
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(); } } }
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); } } }
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); } } }
public void AssyncInvoke2(ThrWork action) { //Thread t = new Thread(this.AssyncInvoke); //t.Start(action); }
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); }
public Server() { tupleSpace = new TupleSpaceSMR(); tpool = new ThreadPool(5, 10); work = null; }
public void AssyncInvoke2(ThrWork action) { //Thread t = new Thread(this.AssyncInvoke); //t.Start(action); }
public void AssyncInvoke(ThrWork action) { // TODO }
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); } } }
/* * Method for asynchronous execution of the delegate ThrWork. * Writes requests into the request queue. */ public void AssyncInvoke(ThrWork action) { _requestsQueue.WriteRequest(action); }
public void AssyncInvoke(ThrWork action) { buf.Produce(action); Console.Write("Request Started"); }
public void AssyncInvoke(ThrWork action) { buf.Produce(action); }
public void AssyncInvoke(ThrWork action) { buf.Produce(action); Console.WriteLine("Submitted action"); }
public void AssyncInvoke(ThrWork action) { if (buffer.Count != 0 && buffer.Capacity == buffer.Count) { buffer.RemoveAt(0); } buffer.Add(action); }
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 } } }