当前位置: 首页 > 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.yayakq.cn/news/874313/

相关文章:

  • 网站建设服务范围网站开发的上市公司有哪些
  • c sql网站开发ppt哪个网站做的好
  • 怎么做网站报价表用dw可以做网站吗
  • 网站免费虚拟主机申请企业网站建设规划方案
  • 如何做律师网站seo搜索引擎优化工程师招聘
  • 关于电视剧的网站设计网页25个经典网站源代码
  • 织梦网做企业网站需要授权吗做一个网站建设的流程
  • 学校 门户网站建设方案godaddy托管wordpress
  • 外贸做网站用什么泰州网站设计咨询
  • 二手房中介网站建设交互式网站是什么意思
  • 新乡网站建设哪家便宜阿里云云服务器 网站配置
  • 萍乡企业网站建设电子商务推广网站
  • 河南企业网站推广免费域名x网站
  • 深圳城乡和住房建设局网站煎蛋网 wordpress
  • 网站是用什么技术做的做徽章的企业网站
  • 民权做网站的公司基础网页制作
  • 服装网站建设目标客户免费漂亮ppt模板下载
  • 上海哪家做网站wordpress打开页面慢
  • 旅游网站建设的详细方案网站框架图怎么做
  • 网站做搜索关键字好吗网站优化 北京
  • 做网站必须网站备案网站制作公司合肥
  • 泰州网站设计培训wordpress更换域名后图片不显示
  • asp.net网站的404错误页面物流企业网站模板免费下载
  • 网站建设优化开发公司永州网站建设哪家好
  • pc网站转换手机网站wap凡科送审平台登录入口
  • wordpress设置站点地址房屋装修设计费一般多少
  • 做网站封面要怎么做建设美团网站
  • 智慧景区网站建设在线资源
  • 上杭县建设局网站不易重名的公司名字
  • 江苏建筑网站上海网站建设seo1888