Skip to main content
GameDev.net gamedev.net
🔒 Locked

Something about CWinThread

Started by Janju Jan 14, 2003 at 9:08 AM 1 replies 300+ views
Original Post
Janju
Janju
What happens if i call:
// First i have a globel function somewhere:
UINT ThreadOne(LPVOID param)
{
   return 0;
}
 
// And in some of my weird OnSomeCrap() function i call:
AfxBeginThread(ThreadOne,this,0,0,0,NULL);  
What happens if i am not catching the returned "CWinThread *" from the AfxBeginThread(...)? Do i have a problem then? I mean is the thread destroyed/killed after the funtion ThreadOne returns?
// Would that be any better?:
UINT ThreadOne(LPVOID param)
{
   AfxEndThread(0);
   return 0;
} 
Would that solve the problem? [edited by - Jonus on January 14, 2003 10:12:45 AM]
Stoffel
Stoffel
Using AfxEndThread is one way to go about doing it. Another method is to just set its m_bAutoDelete member to true, and then you don''t need to call any special function before exitting (useful if you have multiple exit points).

You''d only need the CWinThread-derived object if you were using it to store thread information, e.g. a worker thread was filling out a structure of data, and you need that data after the thread''s done. You''re also unable to get the thread''s return value. The pointer is also used to communicate with the thread from another thread. If you don''t need any of this, there''s no problem with not storing the pointer at all, as long as you get it deleted by one of the two methods above.

Think Liberally..
Janju
Janju
Ok, thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.