Win控制台(多线程)

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

void ThreadFunc1(PVOID param)
{ 
    while(1)
    {
        char *p;
        p=(char *) param;
        Sleep(10);
        out<<p<<"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;
}

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

posted @ 2012-04-27 15:41  Dsp Tian  阅读(1467)  评论(0编辑  收藏  举报