Esempio n. 1
0
void TThreadExecutor::TExecutorThread::Run() {
	while (true) {
		try {
			// get a task
			PRunnable Runnable = Executor->WaitForTask();
			// check if the executor was terminated
			if (Runnable.Empty()) { break; }
			// run the task
			Runnable->Run();
		} catch (const PExcept& Except) {
			Notify->OnNotifyFmt(TNotifyType::ntErr, "Exception in worker thread: %s", Except->GetMsgStr().CStr());
		}
	}

	Notify->OnNotifyFmt(TNotifyType::ntInfo, "Thread %ld exiting finished ...", GetThreadId());
}
Esempio n. 2
0
void TThreadExecutor::Execute(const PRunnable& Runnable) {
	if (Runnable.Empty()) { return; }

	Lock.Lock();

	Notify->OnNotify(TNotifyType::ntInfo, "Adding new runnable to queue ...");
	TaskQ.Push(Runnable);
	Lock.Signal();

	int QSize = TaskQ.Len();

	Lock.Release();

	if (QSize > 0 && QSize % 100 == 0) {
		Notify->OnNotifyFmt(TNotifyType::ntWarn, "Task queue has %ld pending tasks!", QSize);
	}
}