zoukankan      html  css  js  c++  java
  • windows自带的线程池

    #define  _CRT_SECURE_NO_WARNINGS 
    #include "iostream"
    #include "windows.h"
    using namespace std;
    
    void NTAPI poolThreadFunc(
        _Inout_ PTP_CALLBACK_INSTANCE Instance,
        _Inout_opt_ PVOID Context)
    {
        cout << GetCurrentThreadId() << endl;
    }
    
    void NTAPI poolThreadWork(
        _Inout_ PTP_CALLBACK_INSTANCE Instance,
        _Inout_opt_ PVOID Context,
        _Inout_ PTP_WORK Work)
    {
        cout << GetCurrentThreadId() << endl;
    }
    
    int main()
    {
        //创建线程池
    //    PTP_POOL threadPool = CreateThreadpool(NULL);
    //    SetThreadpoolThreadMinimum(threadPool, 1);
    //    SetThreadpoolThreadMaximum(threadPool, 3);
        //初始化环境
        TP_CALLBACK_ENVIRON te;
        InitializeThreadpoolEnvironment(&te);
    //    SetThreadpoolCallbackPool(&te, threadPool);
        //创建线程
        //TrySubmitThreadpoolCallback(poolThreadFunc, NULL, &te);  //单次工作提交,以异步的方式运行函数,一次性任务
        //TrySubmitThreadpoolCallback(poolThreadFunc, NULL, &te);
        //TrySubmitThreadpoolCallback(poolThreadFunc, NULL, &te);
        //TrySubmitThreadpoolCallback(poolThreadFunc, NULL, &te);
        
        //清理线程池的环境变量
    //    DestroyThreadpoolEnvironment(&te);
        //关闭线程池
    //    CloseThreadpool(threadPool);
    
    //    SuspendThread();   //更改线程状态为悬挂
    //    ResumeThread();    //恢复线程状态运行
    
        /*
        创建工作项
        */
        PTP_WORK pwk;
        pwk = CreateThreadpoolWork(poolThreadWork, NULL, &te);
         //提交工作项,可以提交多次
        SubmitThreadpoolWork(pwk);
        SubmitThreadpoolWork(pwk);
        //等待工作结束
        WaitForThreadpoolWorkCallbacks(pwk, false);
        //关闭工作对象
        CloseThreadpoolWork(pwk);
        
        system("pause");
        return 0;
    }
  • 相关阅读:
    Oracle ROWID格式及rdba
    Solaris10上配置log server
    Powerpath的IO路径工作模式
    hagui启动时报警VRTSjre15: not found
    stty设置终端参数
    Jumpstart安装报错:Warning: Could not find matching rule in rules.ok
    解决xmanager无法连接Solaris10的问题
    Solaris10下syslogng安装配置
    VS2005 常用的快捷键
    物理路径和虚拟路径 的访问
  • 原文地址:https://www.cnblogs.com/phpzhou/p/5941492.html
Copyright © 2011-2022 走看看