|
From: Raghunath Marella.S <ms...@ya...> - 2002-06-16 05:21:51
|
Thanks Abhijit.
Is there any function call like join() of java, in
C++.
regards,
Raghunath
--- Abhijit Shylanath <mu...@gm...> wrote:
> You're not giving enough time for the threads to
> start. As soon as you
> create them, the main() process ends, so the threads
> are destroyed. Put a
> delay, either using a Sleep() or MessageBox()
> function, as show below. Try
> clicking the OK button in the 'waiting' message-box
> to see what happens to
> the threads, they're stopped without being
> completed. The new code is here:
>
> #include <iostream.h>
> #include <stdlib.h>
> #include <windows.h>
> #include <conio_mingw.h>
>
> DWORD WINAPI ThreadProc(LPVOID );
>
> int 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.";
> }
> }
> MessageBox(NULL, "Click to close.", "Waiting",
> MB_OK);
> return 0;
> }
>
> 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;
> }
>
> return 0;
> }
>
> PS: Note that using void main() is WRONG!!! It
> should be int main(), and int
> only. It may run on some platforms, but it won't run
> on all. Also, in MingW,
> you have to use conio_mingw.h, but this is very
> platform and compiler
> specific.
>
>
>
_______________________________________________________________
>
> Sponsored by:
> ThinkGeek at http://www.ThinkGeek.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
|