- /* Wait for all worker threads to die. */
- for (;;) {
- EnterCriticalSection(&ioMan->manLock);
- num = ioMan->numWorkers;
- LeaveCriticalSection(&ioMan->manLock);
- if (num == 0)
- break;
- Sleep(10);
+ if (wait_threads) {
+ /* Wait for all worker threads to die. */
+ for (;;) {
+ EnterCriticalSection(&ioMan->manLock);
+ num = ioMan->numWorkers;
+ LeaveCriticalSection(&ioMan->manLock);
+ if (num == 0)
+ break;
+ Sleep(10);
+ }
+ FreeWorkQueue(ioMan->workQueue);
+ CloseHandle(ioMan->hExitEvent);
+ free(ioMan);
+ ioMan = NULL;