Win控制台(多线程)

#include 
#include  /* _beginthread, _endthread */
#include 
#include 
#include <string>
using namespace std;
ofstream out("out.txt");

void ThreadFunc1(PVOID param)
{ 
    while(1)
    {
        char *p;
        p=(char *) param;
        Sleep(10);
        out<"This was draw by thread l"<<endl;
    }
}
void ThreadFunc2(PVOID param)
{ 
    while(1)
    {
        Sleep(10);
        out<<"This was draw by thread 2"<<endl;
    }
}
void ThreadFunc3(PVOID param)
{ 
    while(1)
    {
        Sleep(10);
        out<<"This was draw by thread 3"<<endl;
    }
}
void ThreadFunc4(PVOID param)
{ 
    while(1)
    {
        Sleep(10);
        out<<"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);
    Sleep(1000);
    out<<"end";
    return 0;
}

别人的程序,工作中需要用到多线程。

转载于:https://www.cnblogs.com/tiandsp/archive/2012/04/27/2473657.html

你可能感兴趣的:(Win控制台(多线程))