윈도우즈 멀티스레드 프로그래밍 -----1.네 개의 라인이 동시에 출력//파일 하나 (파라미터 없음 + 파라미터 있음)

5192 단어
/*******************************************************
*             MFC    ,       MFC             ?            :

   Windows API             CreateThread,      :

hThread = CreateThread (&security_attributes, dwStackSize, ThreadProc,pParam, dwFlags, &idThread) ; 

        SECURITY_ATTRIBUTES        。 Windows 98      。 Windows NT ,    NULL。                  ,    0。      ,Windows             。

CreateThread                。        ,           :

DWORD WINAPI ThreadProc (PVOID pParam) ; 
    
CreateThread          ThreadProc   。                 。
  
CreateThread         0,                CREATE_SUSPENDED。         ResumeThread          。          ,       ID    。
	
   Windows         PROCESS.H        C         _beginthread。      :
	  
hThread = _beginthread (ThreadProc, uiStackSize, pParam) ; 
		
    ,            ,          :
		  
void __cdecl ThreadProc (void * pParam) ; 
			
       Windows   ,   「Project Settings」         。  「C/C++」    ,
   「Category」          「Code Generation」。
 「Use Run-Time Library」        ,      「Release」   
「Single-Threaded」   Debug   「Debug Single-Threaded」。
       「Multithreaded」 「Debug Multithreaded」。
          /MT,                    。

                 ,           : 
Email:[email protected] 
Thanks! 

* deom1---           (      ) 
*
*
***********************************************************/
#if 0
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;



void ThreadFunc1(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread l"<<endl;
		cout<<"This was draw by thread l"<<endl;
	}
}

void ThreadFunc2(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread 2"<<endl;
		cout<<"This was draw by thread 2"<<endl;
	}
}

void ThreadFunc3(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread 3"<<endl;
		cout<<"This was draw by thread 3"<<endl;
	}
}

void ThreadFunc4(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread 4"<<endl;
		cout<<"This was draw by thread 4"<<endl;
	}
}

int main()
{
	int i=0;
	_beginthread(ThreadFunc1,0,NULL);
	_beginthread(ThreadFunc2,0,NULL);
	_beginthread(ThreadFunc3,0,NULL);
	_beginthread(ThreadFunc4,0,NULL);
	getch();
	cout<<"end";
	return 0;
}
#endif


#if 1
/*******************************************************
*
* deom2---           (     ) 
*
*
***********************************************************/
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>

using namespace std;


#ifndef ULONG
#define ULONG unsigned long
#endif //ULONG

#define SECOND 1000 //  Sleep(SECOND)       

/* 0,  ,1   */
ULONG g_ulSignal = 0;//       ,        

//ofstream out("out.txt");

//ofstream out("out.txt");

void ThreadFunc1(PVOID param)
{
	while(1)
	{
		char *p;
		p=(char *) param;
		Sleep(SECOND);
		//out<<p<<"This was draw by thread l"<<endl;
		cout<<p<<"This was draw by thread l"<<endl;
	}
}

void ThreadFunc2(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread 2"<<endl;
		cout<<"This was draw by thread 2"<<endl;
	}
}

void ThreadFunc3(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread 3"<<endl;
		cout<<"This was draw by thread 3"<<endl;
	}
}

void ThreadFunc4(PVOID param)
{
	while(1)
	{
		Sleep(SECOND);
		//out<<"This was draw by thread 4"<<endl;
		cout<<"This was draw by thread 4"<<endl;
	}
}

int main()
{
	char *pstr="       
"; _beginthread(ThreadFunc1,0,pstr); _beginthread(ThreadFunc2,0,NULL); _beginthread(ThreadFunc3,0,NULL); _beginthread(ThreadFunc4,0,NULL); getch(); return 0; } #endif //#if 0

좋은 웹페이지 즐겨찾기