/// <summary> /// /// </summary> private void wakeupWorker() { AsyncWorker worker = null; if (_idleWorkers.Count > 0) { Monitor.Enter(_idleWorkers); //++ worker = _idleWorkers[0]; _idleWorkers.RemoveAt(0); Monitor.Exit(_idleWorkers); //-- Monitor.Enter(worker); //++ worker.status = AsyncWorker.Status.Working; Monitor.Pulse(worker); // Pulse Monitor.Exit(worker); //-- } else { /* for (int i = 0; i < _workerPool.Count; ++i) { worker = _workerPool[i]; if (worker.status == AsyncWorker.Status.Ready) break; else worker = null; } // for if (worker != null) { worker.launch(); } else //*/ if (_workerPool.Count < _maxConcurrent) { //Log.debug("launch new worker!!!!!!!!!!!!!!!!!!!"); worker = new AsyncWorker(this); worker.launch(); _workerPool.Add(worker); } } }
public Errno ensureLaunchedWorkers(sbyte n) { Errno err = ((n >= 0 && n <= _maxConcurrent) ? Errno.OK : Errno.InvalidArg); if (err == Errno.OK && n > _workerPool.Count) { AsyncWorker worker = null; int num = n - _workerPool.Count; while (num-- > 0) { worker = new AsyncWorker(this); worker.launch(); _workerPool.Add(worker); } } Debug.Assert(err == Errno.OK); return err; }