How to Create two simultaneously running threads in VC++

Discussion in 'MFC' started by sudhavarma, Nov 15, 2006.

  1. sudhavarma

    sudhavarma New Member

    Joined:
    Nov 3, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bangalore
    Can anyone of me tell me how to create two threads in vc++, one thread should record the audio from microphone and copy to a buffer and the other should read from the buffer and play. These have to run simultaneously. There and be 10 buffers where the recorded data is copied, one played from a buffer the same can be used to record again.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The following code snippet does that
    Code:
    DWORD CPipeSampleDlg::CreatePipeThread()
    {
    	DWORD dwThreadId = 0;
    
    	m_hPipeThread = ::CreateThread(0, 0, (LPTHREAD_START_ROUTINE)StartPipeThread, this, CREATE_SUSPENDED, &dwThreadId);
    	ASSERT(m_hPipeThread);
    
    	::SetThreadPriority(m_hPipeThread,THREAD_PRIORITY_IDLE);
    
    	if( !m_hPipeEvent )
    		m_hPipeEvent = ::CreateEvent( NULL, FALSE, FALSE, _T("StartUpdateDirectoryThread") );
    	else
    		::ResetEvent(m_hPipeEvent);
    	
    	::ResumeThread(m_hPipeThread);
    
    	return dwThreadId;
    }
    This is the code snippet from the following sample [thread=864]Interprocess communication through Named pipes[/thread]. You can download the sample and see it working as well.
     
  3. evileye

    evileye New Member

    Joined:
    Jan 7, 2007
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    0
    Is this thread supposed to be in PROGRAMMING forums?

    Correct me if i am wrong!
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Moved to MFC-Win32 Forums
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice