internal DedicatedThreadPoolSupervisor(DedicatedThreadPool pool) { //don't set up a timer if a timeout wasn't specified if (pool.Settings.DeadlockTimeout == null) { return; } _timer = new Timer(_ => { //bail in the event of a shutdown if (pool.ShutdownRequested) { return; } for (var i = 0; i < pool.Workers.Length; i++) { var w = pool.Workers[i]; if (Interlocked.Exchange(ref w.Status, 0) == 0) { //this requests a new new worker and calls ForceTermination on the old worker //Potential problem here: if the thread is not dead for real, we might abort real work.. there is no way to tell the difference between //deadlocked or just very long running tasks var newWorker = pool.RequestThread(w, i); continue; } //schedule heartbeat action to worker pool.Workers[i].AddWork(() => Interlocked.Increment(ref w.Status)); } }, null, pool.Settings.DeadlockTimeout.Value, pool.Settings.DeadlockTimeout.Value); }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery) { _work = work; _pool = pool; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) { return; } action(); } catch (Exception ex) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; _thread.Start(); }
public PoolWorker(DedicatedThreadPool pool, int workerId) { _pool = pool; _threadExit = new TaskCompletionSource <object>(); #if UNSAFE_THREADING var thread = new Thread(RunThread, pool.Settings.ThreadMaxStackSize); #else var thread = new Thread(RunThread); #endif thread.IsBackground = pool.Settings.ThreadType == ThreadType.Background; if (pool.Settings.Name != null) { thread.Name = string.Format("{0}_{1}", pool.Settings.Name, workerId); } #if UNSAFE_THREADING if (pool.Settings.ApartmentState != ApartmentState.Unknown) { thread.SetApartmentState(pool.Settings.ApartmentState); } #endif thread.Start(); }
private void Failover(bool errorRecovery = false) { /* request a new thread then shut down */ _pool.RequestThread(_work, errorRecovery); CurrentWorker = null; _work = null; _workQueue = null; _pool = null; }
public PoolWorker(DedicatedThreadPool pool, int workerId) { _pool = pool; _threadExit = new TaskCompletionSource <object>(); var thread = new Thread(RunThread) { IsBackground = pool.Settings.ThreadType == ThreadType.Background, }; if (pool.Settings.Name != null) { thread.Name = string.Format("{0}_{1}", pool.Settings.Name, workerId); } thread.Start(); }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery, int workerNumber) { _work = work; _pool = pool; _workerNumber = workerNumber; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { Thread.CurrentThread.Name = string.Format("{0}_{1}", pool.Settings.Name, _workerNumber); CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) { return; } action(); } catch (Exception) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; if (_pool.Settings.ApartmentState != ApartmentState.Unknown) { _thread.SetApartmentState(_pool.Settings.ApartmentState); } _thread.Start(); }
public PoolWorker(DedicatedThreadPool pool, int workerId) { _pool = pool; _threadExit = new TaskCompletionSource <object>(); var thread = new Thread(RunThread, pool.Settings.ThreadMaxStackSize); thread.IsBackground = pool.Settings.ThreadType == ThreadType.Background; thread.Priority = pool.Settings.ThreadPriority; if (pool.Settings.Name != null) { thread.Name = string.Format("{0}_{1}", pool.Settings.Name, workerId); } if (pool.Settings.ApartmentState != ApartmentState.Unknown) { thread.SetApartmentState(pool.Settings.ApartmentState); } thread.Start(); }
public override void Shutdown() { // shut down the dedicated threadpool and null it out Volatile.Write(ref _shuttingDown, 1); _dedicatedThreadPool?.Dispose(); _dedicatedThreadPool = null; }
public ForkJoinExecutor(string id, DedicatedThreadPoolSettings poolSettings) : base(id) { _dedicatedThreadPool = new DedicatedThreadPool(poolSettings); }
public PoolWorker(DedicatedThreadPool pool, int workerId) { _pool = pool; _threadExit = new TaskCompletionSource<object>(); var thread = new Thread(RunThread, pool.Settings.ThreadMaxStackSize); thread.IsBackground = pool.Settings.ThreadType == ThreadType.Background; if (pool.Settings.Name != null) thread.Name = string.Format("{0}_{1}", pool.Settings.Name, workerId); if (pool.Settings.ApartmentState != ApartmentState.Unknown) thread.SetApartmentState(pool.Settings.ApartmentState); thread.Start(); }
/// <summary> /// TBD /// </summary> /// <param name="pool">TBD</param> public DedicatedThreadPoolTaskScheduler(DedicatedThreadPool pool) { _pool = pool; }
public DedicatedThreadPoolTaskScheduler(DedicatedThreadPool pool) { _pool = pool; }
private void Failover(bool errorRecovery = false) { /* request a new thread then shut down */ _pool.RequestThread(_work, errorRecovery); CurrentWorker = null; _work = null; _workQueue = null; _pool = null; }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery) { _work = work; _pool = pool; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) return; action(); } catch (Exception ex) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; _thread.Start(); }
internal DedicatedThreadPoolSupervisor(DedicatedThreadPool pool) { //don't set up a timer if a timeout wasn't specified if (pool.Settings.DeadlockTimeout == null) return; _timer = new Timer(_ => { //bail in the event of a shutdown if (pool.ShutdownRequested) return; foreach (var worker in pool.Workers) { var w = worker; if (Interlocked.Exchange(ref w.Status, 0) == 0) { //this requests a new new worker and calls ForceTermination on the old worker //Potential problem here: if the thread is not dead for real, we might abort real work.. there is no way to tell the difference between //deadlocked or just very long running tasks var newWorker = pool.RequestThread(w); continue; } //schedule heartbeat action to worker worker.AddWork(() => { Interlocked.Increment(ref w.Status); }); } }, null, pool.Settings.DeadlockTimeout.Value, pool.Settings.DeadlockTimeout.Value); }
public PoolWorker(WorkerQueue work, DedicatedThreadPool pool, bool errorRecovery, int workerNumber) { _work = work; _pool = pool; _workerNumber = workerNumber; _workQueue = _work.WorkQueue; _work.ReplacePoolWorker(this, errorRecovery); _thread = new Thread(() => { Thread.CurrentThread.Name = string.Format("{0}_{1}", pool.Settings.Name, _workerNumber); CurrentWorker = this; foreach (var action in _workQueue.GetConsumingEnumerable()) { try { //bail if shutdown has been requested if (_pool.ShutdownRequested) return; action(); } catch (Exception) { Failover(true); return; } } }) { IsBackground = _pool.Settings.ThreadType == ThreadType.Background }; if (_pool.Settings.ApartmentState != ApartmentState.Unknown) _thread.SetApartmentState(_pool.Settings.ApartmentState); _thread.Start(); }
internal ForkJoinDispatcher(MessageDispatcherConfigurator configurator, DedicatedThreadPoolSettings settings) : base(configurator) { _dedicatedThreadPool = new DedicatedThreadPool(settings); }