What might be the problem in this code
void ThreadFunc2( )
{
char szMsg[80];
wsprintf( szMsg, "Parameter = %s.", "Inside thread func2"
;
MessageBox( NULL, szMsg, "ThreadFunc2", MB_OK );
return 0;
}
void ThreadFunc1( )
{
char szMsg[80];
wsprintf( szMsg, "Parameter = %s.", "Inside thread func1"
;
MessageBox( NULL, szMsg, "ThreadFunc1", MB_OK );
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE)ThreadFunc2, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
if (hThread == NULL)
{
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "main", MB_OK );
}
else
{
WaitForSingleObject( hThread,INFINITE);
CloseHandle( hThread );
}
return 0;
}
void main( void )
{
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
char szMsg[80];
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE)ThreadFunc1, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
if (hThread == NULL)
{
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "main", MB_OK );
}
else
{
_getch();
CloseHandle( hThread );
}
}
HERE THREADs are CREATED BUT THE FUNCTION IS NOT GETTING EXECUTED.....
void ThreadFunc2( )
{
char szMsg[80];
wsprintf( szMsg, "Parameter = %s.", "Inside thread func2"
MessageBox( NULL, szMsg, "ThreadFunc2", MB_OK );
return 0;
}
void ThreadFunc1( )
{
char szMsg[80];
wsprintf( szMsg, "Parameter = %s.", "Inside thread func1"
MessageBox( NULL, szMsg, "ThreadFunc1", MB_OK );
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE)ThreadFunc2, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
if (hThread == NULL)
{
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "main", MB_OK );
}
else
{
WaitForSingleObject( hThread,INFINITE);
CloseHandle( hThread );
}
return 0;
}
void main( void )
{
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
char szMsg[80];
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
(LPTHREAD_START_ROUTINE)ThreadFunc1, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
if (hThread == NULL)
{
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "main", MB_OK );
}
else
{
_getch();
CloseHandle( hThread );
}
}
HERE THREADs are CREATED BUT THE FUNCTION IS NOT GETTING EXECUTED.....