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

织梦可以做论坛网站成品网站源码

织梦可以做论坛网站,成品网站源码,耐克网站建设策划方案,没有网站可以域名备案吗注意看test_hierarchy_lock函数&#xff1a;如果thread t2的不注释&#xff0c;就会报错。 这是因为层级锁 更强调单个线程内上锁的顺序。 线程t2已经获取了hmtx2&#xff0c;再试图获取hmtx1就会因为违反层级顺序而抛出异常。 #include <mutex> #include <thread&g…

注意看test_hierarchy_lock函数:如果thread t2的不注释,就会报错。

这是因为层级锁 更强调单个线程内上锁的顺序。
线程t2已经获取了hmtx2,再试图获取hmtx1就会因为违反层级顺序而抛出异常。

#include <mutex>
#include <thread>
//层级锁
class hierarchical_mutex {
public:explicit hierarchical_mutex(unsigned long value) :_hierarchy_value(value),_previous_hierarchy_value(0) {}hierarchical_mutex(const hierarchical_mutex&) = delete;hierarchical_mutex& operator=(const hierarchical_mutex&) = delete;void lock() {check_for_hierarchy_violation(); // 必须_this_thread_hierarchy_value >= 待获取锁的层级值 当前层级值,才继续_internal_mutex.lock();update_hierarchy_value(); // _this_thread_hierarchy_value 变成 待获取锁的层级值}void unlock() {if (_this_thread_hierarchy_value != _hierarchy_value) {throw std::logic_error("mutex hierarchy violated");}_this_thread_hierarchy_value = _previous_hierarchy_value;_internal_mutex.unlock();}bool try_lock() {check_for_hierarchy_violation();if (!_internal_mutex.try_lock()) {return false;}update_hierarchy_value();return true;}
private:std::mutex  _internal_mutex;//当前层级值unsigned long const _hierarchy_value;//上一次层级值unsigned long _previous_hierarchy_value;//本线程记录的层级值static thread_local  unsigned long  _this_thread_hierarchy_value;void check_for_hierarchy_violation() {if (_this_thread_hierarchy_value <= _hierarchy_value) {throw  std::logic_error("mutex  hierarchy violated");}}void  update_hierarchy_value() {_previous_hierarchy_value = _this_thread_hierarchy_value;_this_thread_hierarchy_value = _hierarchy_value;}
};thread_local unsigned long hierarchical_mutex::_this_thread_hierarchy_value(ULONG_MAX);void test_hierarchy_lock() {hierarchical_mutex  hmtx1(1000);hierarchical_mutex  hmtx2(500);std::thread t1([&hmtx1, &hmtx2]() {std::this_thread::sleep_for(std::chrono::milliseconds(500));hmtx1.lock();hmtx2.lock();hmtx2.unlock();hmtx1.unlock();});std::thread t2([&hmtx1, &hmtx2]() {hmtx2.lock();
//		hmtx1.lock();
//		hmtx1.unlock();hmtx2.unlock();});t1.join();t2.join();
}int main(){test_hierarchy_lock();return 0;
}
http://www.hkea.cn/news/940156/

相关文章:

  • 网吧设计方案seox
  • 谁做网站市场营销专业
  • 慈溪外贸公司网站网络营销就业前景和薪水
  • 电商网站建设实训报告长沙网站seo推广公司
  • 阿里云ecs怎么建网站吉林网站seo
  • 企业营销型网站建设的可行性西安竞价托管
  • 做网站如何适应分辨率网站分析培训班
  • 现在币圈有那些私募网站做的好百度推广账号登陆入口
  • 旅游网站图片营销公司排名
  • 做服务器的网站都有哪些搜狗关键词排名此会zjkwlgs
  • php动态网站开发 唐四薪 答案b站引流推广网站
  • 长沙3天2晚自由行攻略论述搜索引擎优化的具体措施
  • 外汇局网站做结汇申报被逆冬seo课程欺骗了
  • 网站运营配置免费网站在线观看人数在哪直播
  • 什么网站做一手房好系统优化的例子
  • wordpress 插入wordseo排名点击工具
  • 网站推广易网宣seo的主要分析工具
  • 安徽网站定制最大免费广告发布平台
  • 怎么查网站有没有做404公司宣传网页怎么做
  • 靠谱营销网站开发选哪家seo的优点和缺点
  • 企业网站建设论文文献综述百度推广的广告真实可信吗
  • 企业网站优化方式广州最新消息今天
  • 旅游网站开发的意义seo优化方案案例
  • 山东做网站的公司seo数据分析哪些方面
  • 做网站用哪几个端口 比较好百度贴吧官网网页
  • 弹幕网站是怎么做的百度在线翻译
  • 独立网站域名代发关键词包收录
  • 如何建立门户网站百度可以发布广告吗
  • 网站开发毕设文献郑州网站优化顾问
  • 青海建设银行的官方网站自己制作网页的网站