Click here to Skip to main content
16,004,991 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questiona problem on threads Pin
keerthikaaa17-Apr-06 21:15
keerthikaaa17-Apr-06 21:15 
AnswerRe: a problem on threads Pin
Parthiban17-Apr-06 21:23
Parthiban17-Apr-06 21:23 
GeneralRe: a problem on threads Pin
keerthikaaa17-Apr-06 21:29
keerthikaaa17-Apr-06 21:29 
GeneralRe: a problem on threads Pin
Stephen Hewitt17-Apr-06 21:35
Stephen Hewitt17-Apr-06 21:35 
AnswerRe: a problem on threads Pin
Stephen Hewitt17-Apr-06 21:25
Stephen Hewitt17-Apr-06 21:25 
GeneralRe: a problem on threads Pin
keerthikaaa17-Apr-06 21:34
keerthikaaa17-Apr-06 21:34 
GeneralRe: a problem on threads Pin
Parthiban17-Apr-06 21:41
Parthiban17-Apr-06 21:41 
GeneralRe: a problem on threads Pin
Stephen Hewitt17-Apr-06 21:44
Stephen Hewitt17-Apr-06 21:44 
You have to be very careful. He's why:
// Bad code!!!
void ThreadRoute1( void* arg )
{
	int *pInt = reinerpret_cast<int*>(arg);
	// Use 'pInt' here...
}
 
// Call to start thread.
{
	int v = 1;
	_beginthread(ThreadRoute1, 0, reinterpret_cast<int*>(&v));
} // After this point "v" no longer exists.


This is a recipe for disaster because for all you know the parent thread can make it to the point where "v" is out of scope before it is accessed in the child thread. This is why I use new in my previous example. He's a reworked version.

void ThreadRoute1( void* arg )
{
	int *pInt = reinerpret_cast<int*>(arg);
	// Use pInt.
	delete pInt;
}
 
// Call to start thread.
int *pInt = new int(1);
if ( _beginthread(ThreadRoute1, 0, reinterpret_cast<void*>(pInt)) == -1 )
{
	delete pInt;
}



Steve
QuestionHow to repaint all child windows from CMainFrame? Pin
Sarvan AL17-Apr-06 21:09
Sarvan AL17-Apr-06 21:09 
AnswerRe: How to repaint all child windows from CMainFrame? Pin
Parthiban17-Apr-06 21:15
Parthiban17-Apr-06 21:15 
GeneralRe: How to repaint all child windows from CMainFrame? Pin
Sarvan AL17-Apr-06 21:32
Sarvan AL17-Apr-06 21:32 
QuestionCreate Mutiple Insatnces of same control Pin
RockyJames17-Apr-06 20:27
RockyJames17-Apr-06 20:27 
AnswerRe: Create Mutiple Insatnces of same control Pin
Cedric Moonen17-Apr-06 20:57
Cedric Moonen17-Apr-06 20:57 
AnswerRe: Create Mutiple Insatnces of same control Pin
Parthiban17-Apr-06 21:10
Parthiban17-Apr-06 21:10 
QuestionParallel port and MFC application integration Pin
christinalimsw17-Apr-06 20:12
christinalimsw17-Apr-06 20:12 
AnswerRe: Parallel port and MFC application integration Pin
Branislav17-Apr-06 22:18
Branislav17-Apr-06 22:18 
QuestionProblem in - typeid - in Release version Pin
Sarvan AL17-Apr-06 18:48
Sarvan AL17-Apr-06 18:48 
AnswerRe: Problem in - typeid - in Release version Pin
Stephen Hewitt17-Apr-06 19:24
Stephen Hewitt17-Apr-06 19:24 
AnswerRe: Problem in - typeid - in Release version Pin
Maxwell Chen17-Apr-06 19:25
Maxwell Chen17-Apr-06 19:25 
GeneralRe: Problem in - typeid - in Release version Pin
Stephen Hewitt17-Apr-06 19:33
Stephen Hewitt17-Apr-06 19:33 
GeneralRe: Problem in - typeid - in Release version Pin
Sarvan AL17-Apr-06 20:12
Sarvan AL17-Apr-06 20:12 
AnswerRe: Problem in - typeid - in Release version Pin
David Crow18-Apr-06 3:02
David Crow18-Apr-06 3:02 
QuestionCHotKeyCtrl and "space" Pin
Abin17-Apr-06 17:50
Abin17-Apr-06 17:50 
AnswerRe: CHotKeyCtrl and "space" Pin
Branislav17-Apr-06 23:04
Branislav17-Apr-06 23:04 
QuestionHow to add drag/drop to the CTreeCtrl. Pin
megzhou17-Apr-06 17:45
megzhou17-Apr-06 17:45 

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.