ThreadPool::~ThreadPool() { waitAll(); // this is the hint for all available threads to break SDL_mutexP(mutex); // lock to be sure that every thread is outside that region, we could get crashes otherwise nextAction = NULL; quitting = true; SDL_CondBroadcast(awakeThread); for(std::set<ThreadPoolItem*>::iterator i = availableThreads.begin(); i != availableThreads.end(); ++i) { SDL_mutexV(mutex); SDL_WaitThread((*i)->thread, NULL); SDL_mutexP(mutex); SDL_DestroyCond((*i)->finishedSignal); SDL_DestroyCond((*i)->readyForNewWork); delete *i; } availableThreads.clear(); SDL_mutexV(mutex); SDL_DestroyMutex(startMutex); SDL_DestroyCond(threadStartedWork); SDL_DestroyCond(threadStatusChanged); SDL_DestroyCond(awakeThread); SDL_DestroyMutex(mutex); }
int lanzarErrores(int* arrayHijos, int argc, char** argv){ int i = start(); for(;i < size -1 ; i++){ if(arrayHijos[i] != 0){ arrayHijos[i] = fork(); if(arrayHijos[i] == 0) copiar(argv[i], argv[argc-1]); } } i = start(); for(; i < size - 1; i++){ waitAll(arrayHijos); } return 0; }
__declspec(noinline) bool benchmark_ntp_workQueue_fs_stat() { NewThreadPoolApi::PrivatePoolEnvironment ppe; ppe.setMin(numProcessors); ppe.setMax(numProcessors); ppe.setPriority(TP_CALLBACK_PRIORITY::TP_CALLBACK_PRIORITY_HIGH); //auto waitQueue = ppe.createWaitQueue(); //auto workQueue = ppe.createWorkQueue(WorkCallback, nullptr); auto workQueue = ppe.createWorkQueue([](PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work) { fs_stat(); }); //auto timerQueue = ppe.createTimerQueue(); for(int r = 0; r < numBenchmarkRepetitions; r++) { auto start = __rdtsc(); for(int i = 0; i < numRequests; i++) { workQueue.submit(); } workQueue.waitAll(); auto finish = __rdtsc(); wprintf(L"start to finish: %f seconds\n", static_cast<double_t>(finish - start) / 3300000000.0); } return false; }
int main(int argc, char** argv){ size = argc; int arrayHijos[size]; if(strcmp(argv[1], "-f")==0){ gotF = 1; } if(strcmp(argv[1], "-q")==0){ gotQ = 1; } if(strcmp(argv[1], "-r")==0){ gotR = 1; } int i = start(); for(;i < argc-1; i++){ arrayHijos[i] = fork(); if(arrayHijos[i]==0)copiar(argv[i], argv[argc-1]); } i = start(); for(; i < argc - 1; i++){ waitAll(arrayHijos); } if(gotR == 1){ i = start(); for(; i < argc - 1; i++){ if(arrayHijos[i] != 0){ if(error()==1){ lanzarErrores(arrayHijos, argc, argv); i = start(); } else { return -1; } } } } return 0; }
boolean waitAll(size_t count, KangarooMonitor* monitors[], int32_t timeoutMS) { KangarooTimeout timeout(timeoutMS); return waitAll(count, monitors, timeout); }