diff options
author | Simon Marlow <simonmar@microsoft.com> | 2006-08-25 08:44:35 +0000 |
---|---|---|
committer | Simon Marlow <simonmar@microsoft.com> | 2006-08-25 08:44:35 +0000 |
commit | 610de7d17e09318272b7516bd9b97e8b2cbd170c (patch) | |
tree | 68dc1bbe4707688bdc7aa74ab12ce7c591e4c64a /rts/win32/IOManager.c | |
parent | edad06244b0a542d6b5c9ce3f3cd72941c5be804 (diff) | |
download | haskell-610de7d17e09318272b7516bd9b97e8b2cbd170c.tar.gz |
Free Win32 Handles on shutdown
patch from #878
Diffstat (limited to 'rts/win32/IOManager.c')
-rw-r--r-- | rts/win32/IOManager.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/rts/win32/IOManager.c b/rts/win32/IOManager.c index a67c3504c1..e69b8bc885 100644 --- a/rts/win32/IOManager.c +++ b/rts/win32/IOManager.c @@ -80,6 +80,9 @@ IOWorkerProc(PVOID param) if (rc == WAIT_OBJECT_0) { // we received the exit event + EnterCriticalSection(&iom->manLock); + ioMan->numWorkers--; + LeaveCriticalSection(&iom->manLock); return 0; } @@ -435,12 +438,23 @@ AddProcRequest ( void* proc, void ShutdownIOManager ( void ) { - SetEvent(ioMan->hExitEvent); - // ToDo: we can't free this now, because the worker thread(s) - // haven't necessarily finished with it yet. Perhaps it should - // have a reference count or something. - // free(ioMan); - // ioMan = NULL; + int num; + + SetEvent(ioMan->hExitEvent); + + /* 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; } /* Keep track of WorkItems currently being serviced. */ |