CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Location
    Morelia, Mexico
    Posts
    40

    wait for thread to finish

    Situation:

    I have a program (prog1) that needs to call some command line programs (prog2), and it needs to wait for them to finish in order to proceed with another tasks.

    Right now i'm using a loop receiving the messages from the thread, which increases cpu utilization of the prog1.

    Is there a way to sending prog1 to a blocked state and awake it when prog2 finishes?

    I know how to do it in linux with forked processes, but i'm a bit novice when it comes to windows and threads.

    This is what i'm doing right now:

    Code:
    CreateProcess(NULL,"COBASQL entcobol.cob salsql.sql",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&siInfo,&piInfo);
    EsperaATerminacionProceso(piInfo.hThread);
    And the waiting function:
    Code:
    void CTransftpDlg::EsperaATerminacionProceso(HANDLE hThread)
    {
    	DWORD dwRet;
    	MSG msg;
    	do
    	{
    		dwRet = ::MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
    		if (dwRet != WAIT_OBJECT_0)
    		{
    			while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
    			{
    				TranslateMessage(&msg);
    				DispatchMessage(&msg);
    			}
    
    		}
    	} while ((dwRet != WAIT_OBJECT_0) && (dwRet != WAIT_FAILED));
    }
    Thanks in advance.
    Last edited by Luis G; April 21st, 2003 at 03:14 PM.
    int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
    o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

  2. #2
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    1,384
    Have a look at this FAQ .
    Regards,
    Usman.

  3. #3
    Join Date
    Apr 2003
    Location
    Morelia, Mexico
    Posts
    40
    Thanks a lot, right now i'm reading other questions of that FAQ, a couple of tests using that approach reduced the cpu utilization to 15% (instead of 100%), and most of that 15% is used by prog2.

    If there's a mod around, feel free to delete this thread, 'cause the question is already in the FAQ.
    int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
    o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured