线程池面试题_动态线程池

线程池面试题_动态线程池线程池QueueUserWorkItem

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

  1. // Test1.cpp : Defines the entry point for the console application.  
  2. //  
  3.   
  4. #include “stdafx.h”  
  5. #include <assert.h>  
  6. #include <Windows.h>  
  7.   
  8. DWORD WINAPI TestThreadPool(PVOID pContext);  
  9.   
  10. CRITICAL_SECTION g_cs;  
  11.   
  12. int _tmain(int argc, _TCHAR* argv[])  
  13. {  
  14.     InitializeCriticalSection(&g_cs);  
  15.     SECURITY_ATTRIBUTES sa;  
  16.     sa.bInheritHandle = TRUE;  
  17.     sa.nLength = sizeof(SECURITY_ATTRIBUTES);  
  18.     sa.lpSecurityDescriptor = NULL;  
  19.   
  20.     HANDLE hSemaphore = CreateSemaphoreW(&sa, 0 ,1, L“jyytet”);   
  21.   
  22.     for (int i = 0; i < 10; i++)  
  23.     {  
  24.         QueueUserWorkItem(TestThreadPool, L“Hello World”, WT_EXECUTEDEFAULT);  
  25.     }  
  26.     QueueUserWorkItem(TestThreadPool, L“Finish”, WT_EXECUTEDEFAULT);  
  27.   
  28.     WaitForSingleObject(hSemaphore, -1);  
  29.     CloseHandle(hSemaphore);  
  30.     hSemaphore = NULL;   
  31.     DeleteCriticalSection(&g_cs);  
  32.   
  33.     wprintf(L“Game over /r/n”);  
  34.   
  35.     getchar();  
  36.   
  37.     return 0;  
  38. }  
  39.   
  40. DWORD WINAPI TestThreadPool(PVOID pContext)  
  41. {  
  42.     if (NULL == pContext)  
  43.         return 0;  
  44.   
  45.     EnterCriticalSection(&g_cs);  
  46.     wchar_t *pPrintf = (wchar_t *) pContext;  
  47.     wprintf(L“%s /r/n”, pPrintf);  
  48.     Sleep(1000);  
  49.   
  50.     if (wcscmp(pPrintf, L“Finish”) == 0)  
  51.     {  
  52.         HANDLE hSemaphore = OpenSemaphoreW(SEMAPHORE_ALL_ACCESS, FALSE,  L“jyytet”);  
  53.         assert(hSemaphore !=  NULL);  
  54.         ReleaseSemaphore(hSemaphore, 1, NULL);  
  55.         CloseHandle(hSemaphore);  
  56.     }  
  57.     LeaveCriticalSection(&g_cs);  
  58.   
  59.     return 1;  
  60. }  

// Test1.cpp : Defines the entry point for the console application.//#include “stdafx.h”#include <assert.h>#include <Windows.h>DWORD WINAPI TestThreadPool(PVOID pContext);CRITICAL_SECTION g_cs;int _tmain(int argc, _TCHAR* argv[]){ InitializeCriticalSection(&g_cs); SECURITY_ATTRIBUTES sa; sa.bInheritHandle = TRUE; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; HANDLE hSemaphore = CreateSemaphoreW(&sa, 0 ,1, L”jyytet”);  for (int i = 0; i < 10; i++) {  QueueUserWorkItem(TestThreadPool, L”Hello World”, WT_EXECUTEDEFAULT); } QueueUserWorkItem(TestThreadPool, L”Finish”, WT_EXECUTEDEFAULT); WaitForSingleObject(hSemaphore, -1); CloseHandle(hSemaphore); hSemaphore = NULL;  DeleteCriticalSection(&g_cs); wprintf(L”Game over /r/n”); getchar(); return 0;}DWORD WINAPI TestThreadPool(PVOID pContext){ if (NULL == pContext)  return 0; EnterCriticalSection(&g_cs); wchar_t *pPrintf = (wchar_t *) pContext; wprintf(L”%s /r/n”, pPrintf); Sleep(1000); if (wcscmp(pPrintf, L”Finish”) == 0) {  HANDLE hSemaphore = OpenSemaphoreW(SEMAPHORE_ALL_ACCESS, FALSE,  L”jyytet”);  assert(hSemaphore !=  NULL);  ReleaseSemaphore(hSemaphore, 1, NULL);  CloseHandle(hSemaphore); } LeaveCriticalSection(&g_cs); return 1;}

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/189677.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 再次发布一个jq的下拉框式日期选择插件 dateSelector ~

    再次发布一个jq的下拉框式日期选择插件 dateSelector ~

    2021年7月26日
    63
  • Hadoop生态系统功能组件,主要包括哪些?[通俗易懂]

    Hadoop生态系统功能组件,主要包括哪些?[通俗易懂]经过多年的发展,Hadoop生态系统不断完善和成熟,目前已经包括了多个子项目,除了核心的HDFS和MapReduce以外,Hadoop生态系统还包括要ZoopKer、HBase、Hive、Pig、Mahout、Sqoop、Flume、Ambari等功能组件。HDFSHadoop分布式文件系统是Hadoop项目的两大核心之一,是针对谷歌文件系统(GoogleFileSystem,GFS)的开源实…

    2022年5月19日
    42
  • Solidworks介绍与 solidwords 2018安装过程

    Solidworks介绍与 solidwords 2018安装过程SOLIDWORKS 介绍与安装一 什么是 solidworks 二 solidworks 用途三 安装 solidwords 一 什么是 solidworks nbsp nbsp nbsp nbsp SolidWorks 是达索系统 DassaultSyst 下的子公司 SolidWorks 软件是世界上第一个基于 Windows 开发的三维 CAD 系统 软件功能强大 组件繁多 Solidworks 有功能强大 易学易用和技术创新三大特点 这使得 SolidWorks 成为领先的 主流的三维 CAD 解

    2025年8月13日
    2
  • TSQL–临时表和表变量

    TSQL–临时表和表变量

    2021年11月26日
    46
  • oracle number类型 p、s参数说明[通俗易懂]

    oracle number类型 p、s参数说明[通俗易懂] oraclenumber类型采用科学计数法表示,p表示有效数字的个数,s表示精度;如果定义字段类型为number(p,s)则该字段所能表示的最大正数是(10p-1)*10-s最小负数-(10p-1)*10-s;所有该范围之间的数字均可根据精度四舍五入后插入该字段;否则将会报错。  

    2022年7月24日
    7
  • 特斯拉笔试内容_数据库笔试题

    特斯拉笔试内容_数据库笔试题今天笔试一共两道题,1个小时内答出来,第一题如下两张图所示:正确sql为:selectsensor_id,count(distinctevent_type)fromeventsgroupbysensor_idorderbysensor_id效果如下图:第二道题如下两张图:,答案如下sql:selectid,server_name,casewhenconnections>(selectavg(conne…

    2025年6月21日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号