zoukankan      html  css  js  c++  java
  • WaitForMultipleObjects、WaitForSingleObject、GetExitCodeThread

    WaitForMultipleObjects、WaitForSingleObject、GetExitCodeThread

    // Thread.cpp : Defines the entry point for the console application.
    //

    #include 
    "stdafx.h"
    #include 
    <windows.h>

    HANDLE hth[
    2];
    DWORD WINAPI func1(LPVOID p1)
    {
        printf(
    "fun1 end\n");
        DWORD exitC;
        GetExitCodeThread(hth[
    1],&exitC);
        
    if (exitC==STILL_ACTIVE)//还在运行中
        {
            printf(
    "func2 STILL_ACTIVE\n");
        }

        
    return 4;
    }


    DWORD WINAPI func2(LPVOID p2)
    {
        Sleep(
    1000);
        DWORD exitC;
        GetExitCodeThread(hth[
    0],&exitC);
        printf(
    "func1 exit code= %d\nfun2 end\n",exitC);
        
    return 0;
    }


    int main(int argc, char* argv[])
    {
        
        DWORD thID1,thID2;
        printf(
    "Hello World!\n");
        hth[
    0]= CreateThread(NULL,0,func1,0,0,&thID1);
        hth[
    1]= CreateThread(NULL,0,func2,0,0,&thID2);

        WaitForMultipleObjects(
    2,hth,true,INFINITE); //true等待所有线程结束 false 只要有一条线程结束就退出 INFINITE一直等待
        
    //WaitForMultipleObjects(2,hth,false,10000);//INFINITE
        
    //WaitForSingleObject(hth[1],INFINITE);

        
    return 0;
    }


  • 相关阅读:
    ES 2016+
    git-svn for mac
    Linux系统下安装rz/sz命令及使用说明
    Nginx location指令匹配顺序规则
    nginx修改配置后不生效的问题
    ssh and scp从远程服务器下载文件
    安装yii2 框架遇到的问题
    php添加openssl扩展
    GitHub Token for composer
    centos7+nginx+php+mysql环境搭建
  • 原文地址:https://www.cnblogs.com/ahuo/p/891459.html
Copyright © 2011-2022 走看看