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;
    }


  • 相关阅读:
    js实现选择切换
    Jquery操作select
    Mybatis 高级结果映射 ResultMap Association Collection
    jQuery的一些特性和用法
    利用JSONP解决AJAX跨域问题的原理与jQuery解决方案
    List转成Array 连个Array比较
    3.15
    Get 和 Post 方法的选择和URL的设计
    fd
    如何维护一个1000 IP的免费代理池
  • 原文地址:https://www.cnblogs.com/ahuo/p/891459.html
Copyright © 2011-2022 走看看