digitalmars.D.bugs - Thread termination
- Kris (6/6) May 19 2005 I notice on Win32 that the system-level handle created for each new thre...
- Walter (2/8) May 20 2005 If you can suggest a fix to std.thread, I'd appreciate it!
- Unknown W. Brackets (12/14) May 20 2005 I would guess the usage of:
- Sean Kelly (5/8) May 20 2005 Assuming the thread is created via _beginthreadex, you just need to call
- kris (15/27) May 20 2005 Well, you'd typically close the 'hdl' inside std.thread.threadstart(),
I notice on Win32 that the system-level handle created for each new thread is apparently not closed properly. You can see this by slowly creating a number of threads, and inspecting the process handle-count via Task Mgr ~ it increments by one for each thread, but doesn't revert as each thread terminates. This would be become terminal for a thread-pool.
May 19 2005
"Kris" <fu bar.com> wrote in message news:d6jugo$8ga$1 digitaldaemon.com...I notice on Win32 that the system-level handle created for each new thread is apparently not closed properly. You can see this by slowly creating a number of threads, and inspecting the process handle-count via Task Mgr ~ it increments by one for each thread, but doesn't revert as each thread terminates. This would be become terminal for a thread-pool.If you can suggest a fix to std.thread, I'd appreciate it!
May 20 2005
I would guess the usage of: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__endthread.2c_._endthreadex.asp It sounds like this should be called from the thread itself, yes? It also says:when you use _beginthreadex and _endthreadex, you must close thethread handle by calling the Win32 CloseHandle API. Is that happening? Anyway, I guess I would add: _endthreadex(result); Before/instead of: return result; In the Windows part of std.thread's threadstart. But, erm, I haven't worked all that much with threads myself. -[Unknown]If you can suggest a fix to std.thread, I'd appreciate it!
May 20 2005
In article <d6k856$hu8$1 digitaldaemon.com>, Unknown W. Brackets says...I would guess the usage of: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__endthread.2c_._endthreadex.asp It sounds like this should be called from the thread itself, yes?Assuming the thread is created via _beginthreadex, you just need to call CloseHandle on the thread handle before destruction. You can actually close the thread handle any time you want, as this just detaches the thread. Sean
May 20 2005
Walter wrote:"Kris" <fu bar.com> wrote in message news:d6jugo$8ga$1 digitaldaemon.com...Well, you'd typically close the 'hdl' inside std.thread.threadstart(), after the delegate or function had returned. Or during the dtor. That aside, and in looking at the code, I see what appears to be potential for a race-condition between the GC and a terminating thread. When a thread terminates, it null out an entry in an array ... one which resumeAll/pauseAll might currently be inspecting ... and there's no synch. I guess you're relying on 32-bit read/write being atomic? Either way, there'd probably a race condition between CloseHandle and the usage of that handle elsewhere. Placing a CloseHandle in the Thread dtor would at least avoid a race against the GC thread (though it still might against other threads). I imagine you can't synch some of this due to deadlock potential via the GC (it pauses all threads, and then tries to get a mutex held by one of the paused threads).I notice on Win32 that the system-level handle created for each new thread is apparently not closed properly. You can see this by slowly creating a number of threads, and inspecting the process handle-count via Task Mgr ~ it increments by one for each thread, but doesn't revert as each thread terminates. This would be become terminal for a thread-pool.If you can suggest a fix to std.thread, I'd appreciate it!
May 20 2005