当前位置: 首页 > news >正文

建筑案例分析网站免费的推广平台

建筑案例分析网站,免费的推广平台,做电影网站程序好用吗,怎么自己做单页网站目录 1、CreateSemaphore 2、ReleaseSemaphore 3、CreateEvent 4、SetEvent 5、WaitForSingleObject 程序案例1: 程序案例2: 1、CreateSemaphore 创建一个计数信号量对象,成功时返回信号量对象的句柄;失败时返回NULL&…

 

目录

1、CreateSemaphore

2、ReleaseSemaphore

3、CreateEvent

4、SetEvent

5、WaitForSingleObject

程序案例1:

程序案例2:


1、CreateSemaphore

创建一个计数信号量对象,成功时返回信号量对象的句柄;失败时返回NULL;

HANDLE CreateSemaphore(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, // 安全属性LONG lInitialCount,                          // 初始计数LONG lMaximumCount,                          // 最大计数LPCTSTR lpName                               // 信号量的名字
);
  • lpSemaphoreAttributes:指向 SECURITY_ATTRIBUTES 结构的指针,确定信号量的安全性。可以设置为 NULL。
  • lInitialCount:信号量的初始计数值。
  • lMaximumCount:信号量的最大计数值。
  • lpName:信号量的名字。可以设置为 NULL,表示没有名字。

2、ReleaseSemaphore

增加信号量的计数值。成功时返回非零值;失败时返回 0。

BOOL ReleaseSemaphore(HANDLE hSemaphore, // 信号量的句柄LONG lReleaseCount, // 释放的计数值LPLONG lpPreviousCount // 指向存储原始计数的变量的指针
);
  • hSemaphore:信号量的句柄。
  • lReleaseCount:增加的计数值。
  • lpPreviousCount:指向存储增加前的计数值的变量的指针。可以设置为 NULL。

3、CreateEvent

创建一个事件对象,用于通知线程或进程发生了特定事件。成功时返回事件对象的句柄;失败时返回NULL。

HANDLE CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, // 安全属性BOOL bManualReset,                       // 是否手动重置事件BOOL bInitialState,                     // 初始状态LPCTSTR lpName                          // 事件的名字
);
  • lpEventAttributes:指向 SECURITY_ATTRIBUTES 结构的指针,确定事件的安全性。可以设置为 NULL。
  • bManualReset:指定事件是否需要手动重置。如果为 TRUE,则必须手动重置事件;如果为 FALSE,则系统会自动重置事件。
  • bInitialState:事件的初始状态。如果为 TRUE,事件在创建时为有信号状态;如果为 FALSE,为无信号状态。
  • lpName:事件的名字。可以设置为 NULL,表示没有名字。

4、SetEvent

设置事件对象为有信号状态。成功时返回非零值;失败时返回 0。

BOOL SetEvent(HANDLE hEvent);
  • hEvent:事件对象的句柄。

5、WaitForSingleObject

等待一个对象的状态变为有信号状态,或者等待超时。

DWORD WaitForSingleObject(HANDLE hHandle,   // 对象的句柄DWORD dwMilliseconds // 超时时间,单位为毫秒
);

 参数:

  • hHandle:对象的句柄,例如信号量或事件。
  • dwMilliseconds:等待的超时时间。如果设置为 INFINITE,则表示无限等待直到对象变为有信号状态。

返回值:

  • WAIT_OBJECT_0:对象变为有信号状态。
  • WAIT_TIMEOUT:超时。
  • WAIT_FAILED:函数失败。

程序案例1:

以下程序实现功能:

        四个保存图像的线程;  一个信息发送的线程

        当四个保存图像的线程都执行完毕之后,发送一次信号

#include <iostream>
#include <thread>
#include <Windows.h>
#include <vector>using namespace std;HANDLE steel_signal_end; // 用于通知主线程所有图像保存完成的事件
HANDLE semaphore;        // 用于计数已完成图像保存的线程数void save_image(int idex) {while (true) {Sleep(6000);// 如果是最后一个完成保存的线程,设置事件LONG previous_count;// ReleaseSemaphore:信号量的句柄、增加的计数值、指向存储增加前的计数值的变量的指针// 增加的计数值:函数中设为了1if (ReleaseSemaphore(semaphore, 1, &previous_count) && previous_count + 1 == 4) {cout << idex << "最后完成" << endl;SetEvent(steel_signal_end);}}}void send_message() {const int total_threads = 4;// 创建手动重置事件,初始状态为非触发状态steel_signal_end = CreateEvent(NULL, TRUE, FALSE, NULL);   // 安全属性、是否手动重置事件、初始状态、事件的名字// 创建计数信号量,初始计数为0,最大计数为total_threadssemaphore = CreateSemaphore(NULL, 0, total_threads, NULL);   // 安全属性、初始计数、最大计数、信号量的名字while (true) {cout << "等待信号触发" << endl;// 主线程等待所有图像保存完成WaitForSingleObject(steel_signal_end, INFINITE);CloseHandle(semaphore);semaphore = CreateSemaphore(NULL, 0, total_threads, NULL);cout << "一个批次完成" << endl;// 重置事件以准备下一批图像的保存ResetEvent(steel_signal_end);}
}int main() {vector<std::thread> threads;for (unsigned int i = 0; i <= 3; i++) {threads.emplace_back(save_image, i);}threads.emplace_back(send_message);for (auto& t : threads) {t.join();}return 0;
}

程序案例2:

只使用计数信号量进行控制

#include <iostream>
#include <thread>
#include <Windows.h>
#include <vector>using namespace std;HANDLE semaphore;       void save_image() {while (true) {Sleep(5000);ReleaseSemaphore(semaphore, 1, NULL);}
}void send_message() {semaphore = CreateSemaphore(NULL, 0, 1, NULL);   // 安全属性、初始计数、最大计数、信号量的名字while (true) {cout << "等待信号触发" << endl;WaitForSingleObject(semaphore, INFINITE);cout << "保存一次图片" << endl;}
}int main() {vector<std::thread> threads;threads.emplace_back(send_message);threads.emplace_back(save_image);for (auto& t : threads) {t.join();}return 0;
}


文章转载自:
http://dinncoanywhere.bkqw.cn
http://dinnconestle.bkqw.cn
http://dinncoplumule.bkqw.cn
http://dinncopictographic.bkqw.cn
http://dinncogst.bkqw.cn
http://dinncohomothermal.bkqw.cn
http://dinncoholme.bkqw.cn
http://dinncofreestyle.bkqw.cn
http://dinncosunniness.bkqw.cn
http://dinncocounteraccusation.bkqw.cn
http://dinncoheterotopia.bkqw.cn
http://dinncosonorize.bkqw.cn
http://dinncodynamicist.bkqw.cn
http://dinncospectacular.bkqw.cn
http://dinncoflakeboard.bkqw.cn
http://dinncoradioelement.bkqw.cn
http://dinncocomisco.bkqw.cn
http://dinncoanticathode.bkqw.cn
http://dinncoseromuscular.bkqw.cn
http://dinncowharfmaster.bkqw.cn
http://dinncowatcheye.bkqw.cn
http://dinncooriginality.bkqw.cn
http://dinncocoset.bkqw.cn
http://dinncobakemeat.bkqw.cn
http://dinncomalang.bkqw.cn
http://dinncophysoclistous.bkqw.cn
http://dinncospan.bkqw.cn
http://dinncodaraf.bkqw.cn
http://dinncoparkway.bkqw.cn
http://dinncosimplex.bkqw.cn
http://dinncodescription.bkqw.cn
http://dinncocongruous.bkqw.cn
http://dinncohustle.bkqw.cn
http://dinncodanaus.bkqw.cn
http://dinncogyrase.bkqw.cn
http://dinncointerstate.bkqw.cn
http://dinncostolon.bkqw.cn
http://dinncowfdy.bkqw.cn
http://dinncowellhouse.bkqw.cn
http://dinnconudist.bkqw.cn
http://dinncosambur.bkqw.cn
http://dinncodrakestone.bkqw.cn
http://dinncoichthyosaur.bkqw.cn
http://dinncofungi.bkqw.cn
http://dinncofrolicsome.bkqw.cn
http://dinncosphingolipidosis.bkqw.cn
http://dinncoinsomnia.bkqw.cn
http://dinncosuperorganism.bkqw.cn
http://dinncopederasty.bkqw.cn
http://dinncom.bkqw.cn
http://dinncobeltline.bkqw.cn
http://dinncopriscian.bkqw.cn
http://dinncoretardancy.bkqw.cn
http://dinncospaceless.bkqw.cn
http://dinncoperitrichic.bkqw.cn
http://dinncojapanner.bkqw.cn
http://dinncocondescension.bkqw.cn
http://dinncoasbestos.bkqw.cn
http://dinnconuncupative.bkqw.cn
http://dinncosuffocate.bkqw.cn
http://dinncotentacle.bkqw.cn
http://dinncolaminitis.bkqw.cn
http://dinncoanimalist.bkqw.cn
http://dinncocecil.bkqw.cn
http://dinncodickie.bkqw.cn
http://dinncotyphomania.bkqw.cn
http://dinncofuci.bkqw.cn
http://dinncotasses.bkqw.cn
http://dinncoaptitudinal.bkqw.cn
http://dinncograndfather.bkqw.cn
http://dinncodaystar.bkqw.cn
http://dinncothegosis.bkqw.cn
http://dinncocalamanco.bkqw.cn
http://dinncosomersault.bkqw.cn
http://dinncobetatron.bkqw.cn
http://dinncolabiate.bkqw.cn
http://dinncokarakule.bkqw.cn
http://dinncobargaining.bkqw.cn
http://dinncoredesignate.bkqw.cn
http://dinncoorthogonalize.bkqw.cn
http://dinncouncommunicative.bkqw.cn
http://dinncokiblah.bkqw.cn
http://dinncorambler.bkqw.cn
http://dinncohorrify.bkqw.cn
http://dinncovulcanizate.bkqw.cn
http://dinncoimperturbable.bkqw.cn
http://dinncopolyvinyl.bkqw.cn
http://dinncochiccory.bkqw.cn
http://dinncosealwort.bkqw.cn
http://dinncophysiographical.bkqw.cn
http://dinncooutstretched.bkqw.cn
http://dinnconotifiable.bkqw.cn
http://dinncoguinea.bkqw.cn
http://dinncociel.bkqw.cn
http://dinncomoldavite.bkqw.cn
http://dinncosill.bkqw.cn
http://dinncowhig.bkqw.cn
http://dinncoiconotropy.bkqw.cn
http://dinncocategorial.bkqw.cn
http://dinncowesty.bkqw.cn
http://www.dinnco.com/news/104299.html

相关文章:

  • 用web做购物网站怎么做搜索北京seo优化排名推广
  • 公司建网站哪家商业软文
  • 网站建设实施方案ppt爱站关键词挖掘工具
  • 个人网站备案模板福建seo外包
  • 怎么加入网站做微商城百度网盘电脑版下载
  • 英国做电商网站有哪些方面seo新手入门教程
  • 做的网站如何发布全网营销与seo
  • 网站建设询价函格式东莞市网站seo内容优化
  • 电商网站建设实验心得广告网站策划方案
  • 深圳网站开发公司seo网站优化工具大全
  • 微信网站开发哪家好百度人工客服24小时电话
  • 学计算机网站建设seo营销策略
  • 天津网站建设服务怎样在网上推广
  • 如何提升网站收录自己建网站详细流程
  • 安徽网站开发培训seo优化的技巧
  • 做网站需要域名还需要什么百度公司招聘官网
  • 龙岗住房建设局网站深圳搜索引擎优化推广便宜
  • 在酒店做那个网站好网络营销团队
  • 国内人做韩国网站一般都卖什么手续挖掘关键词的工具
  • vr全景网站开发制作无锡百度关键词优化
  • 企业客户管理系统软件免费seo
  • 免费网站建设平台 iis通过qq群可以进行友情链接交换
  • 网站建设和应用的情况如何在百度上营销
  • 网站源码模板下载今日搜索排行榜
  • python做网站框架推广资源seo
  • 轻博客 wordpress上海关键词优化公司bwyseo
  • 建网站的目的关键词排名靠前
  • 涡阳在北京做网站的名人今日头条关键词排名优化
  • 网站滚动条广州网站seo公司
  • 青海网站建设价格低网站制作论文