zoukankan      html  css  js  c++  java
  • 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;
    }

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

  • 相关阅读:
    Shell脚本sed命令
    Shell脚本常用unix命令
    Shell的case语句
    3.5.2 数值之间的转换
    3.5.1 数学函数与常量
    3.5 运算符
    3.4.2 常量
    3.4.1 变量初始化
    3.4 变量
    Python异常捕捉的一个小问题
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2473657.html
Copyright © 2011-2022 走看看