Click here to Skip to main content
15,881,413 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Chesnokov Yuriy16-Sep-09 1:51
professionalChesnokov Yuriy16-Sep-09 1:51 
AnswerRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 1:29
professional Randor 16-Sep-09 1:29 
AnswerRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Chesnokov Yuriy16-Sep-09 1:51
professionalChesnokov Yuriy16-Sep-09 1:51 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 2:29
professional Randor 16-Sep-09 2:29 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Roger Stoltz16-Sep-09 2:55
Roger Stoltz16-Sep-09 2:55 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 3:08
professional Randor 16-Sep-09 3:08 
AnswerRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Roger Stoltz16-Sep-09 4:07
Roger Stoltz16-Sep-09 4:07 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 4:40
professional Randor 16-Sep-09 4:40 
Roger Stoltz wrote:
If the OP's problem was that he called ::WaitForSingleObject() with an invalid handle, it would return immediately with WAIT_FAILED


This is not completely correct. The NT kernel recycles both window and thread identifiers (HANDLES). You can easily test this by creating a test dialog with 2 buttons. On the first button create a thread and on the second button end the thread. Rapidly press the buttons and observe the newly created thread sometimes has the same handle value in your traced output. It is the same for window handles... when they are closed the same value can be assigned to a window created in the near future.

An excerpt from: The Birth of a Thread: CreateThread[^]

Please do not make any assumptions about this identifier; all that is guaranteed is that while the thread is running, no other thread will ever have the same ID. The ID may be recycled later on after the thread has terminated.

Multithreading for Rookies[^]
Give Me a Handle, and I'll Show You an Object[^]

1.) The benefit of your option is the engineer does not need to call DuplicateHandle. On the negative side your option requires the engineer to manually perform the thread cleanup.

2.) The benefit of the other option is the engineer does no cleanup because m_bAutoDelete defaults to TRUE. On the negative side the engineer has to call DuplicateHandle and then CloseHandle when he is done waiting.

Anyway, this debate is meanlingless. If the presented scenario is what is actually occuring then both options presented are good options. This is the beauty of the internet and sites like codeproject.com where professionals can exchange ideas and their experience.

Best Wishes,
-David Delaune
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Roger Stoltz16-Sep-09 5:34
Roger Stoltz16-Sep-09 5:34 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 7:04
professional Randor 16-Sep-09 7:04 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Chesnokov Yuriy16-Sep-09 7:22
professionalChesnokov Yuriy16-Sep-09 7:22 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 7:47
professional Randor 16-Sep-09 7:47 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Roger Stoltz16-Sep-09 7:59
Roger Stoltz16-Sep-09 7:59 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 8:51
professional Randor 16-Sep-09 8:51 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Roger Stoltz16-Sep-09 11:58
Roger Stoltz16-Sep-09 11:58 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Randor 16-Sep-09 12:25
professional Randor 16-Sep-09 12:25 
GeneralRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Roger Stoltz16-Sep-09 12:51
Roger Stoltz16-Sep-09 12:51 
AnswerRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Stuart Dootson16-Sep-09 1:58
professionalStuart Dootson16-Sep-09 1:58 
AnswerRe: WaitForSingleObject(m_SomeThread->m_hThread, INFINITE); Pin
Jeff Archer16-Sep-09 2:47
Jeff Archer16-Sep-09 2:47 
QuestionExiting an MFC ActiveX Pin
Opa Knack15-Sep-09 22:41
Opa Knack15-Sep-09 22:41 
AnswerRe: Exiting an MFC ActiveX Pin
Stuart Dootson16-Sep-09 0:28
professionalStuart Dootson16-Sep-09 0:28 
AnswerRe: Exiting an MFC ActiveX Pin
Roger Stoltz16-Sep-09 0:38
Roger Stoltz16-Sep-09 0:38 
AnswerRe: Exiting an MFC ActiveX Pin
Randor 16-Sep-09 1:13
professional Randor 16-Sep-09 1:13 
QuestionAuto login a user in XP, after logoff Pin
SummerBulb15-Sep-09 21:59
SummerBulb15-Sep-09 21:59 
AnswerRe: Auto login a user in XP, after logoff Pin
«_Superman_»15-Sep-09 22:27
professional«_Superman_»15-Sep-09 22:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.