|
From: Raghunath Marella.S <ms...@ya...> - 2002-06-15 18:32:01
|
Hi,
I am new to multithreading in VC++. I wrote a simple
program to understand the functionality of threads. I
used CreateThread. Actually, I am creating three
threads, and the ThreadProc will print integers from 0
to 10 for each thread. But the program is not working
as expected. The print statements and the getch()
functions are not seem to be working. I am not getting
why this should be? Will any one please clarify why
this is happening so? The code has been attached.
**************************************************
#include <iostream.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
DWORD WINAPI ThreadProc(LPVOID );
void main()
{
for(int i = 0;i<3;i++)
{
DWORD threadId;
HANDLE hThread;
hThread =
CreateThread(NULL,0,ThreadProc,&i,0,&threadId);
if(hThread == NULL)
cout << "\n Thread has not been created";
else
{
//_getch();
cout << "\n Thread has been created successfully.";
}
}
}
DWORD WINAPI ThreadProc( LPVOID lpParam )
{
cout << "\n Entered threadProc...";
MessageBox(NULL,"sample output","",MB_OK);
for(int i = 0;i<10;i++)
{
cout << "\n thread output is:"<<HIWORD(lpParam) <<
".."<<i;
}
_getch();
return 0;
}
***********************************************
thanks & regards,
Raghunath
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
|