Concept        Header     Summary 
    Threads   <thread>  Standard, low-level, type-safe;
    Futures   <future> Via async function, hides threading;
    Locks   <mutex> Standard, low-level locking primitives
    Condition Vars   <condition_variable>  Low-level synchronization primitives
    Atomics   <atomic> Predictable, concurrent access without data race
  • How to avoid data races
  1. redesign to eliminate sharing data
  2. use thread-safe entities(e.g. parallel collections)
  3. use synchronization(e.g. lock atom...)
  • Using RAII( Resource Acquisition Is Initialization ) to avoid data races

old style

#include <mutex>
#include <thread> std::mutex m;
int sum = ; std::thread t1( [&] () {
int r = func();
m.lock();
sum += r;
m.unlock();
});

 using RAII

std::mutex m;
int sum = ; std::thread t1( [&] () {
int r = func();
{
lock_guard<mutex> locker(m);
sum += r;
}
});

C++11 Concurrency Features的更多相关文章

  1. 升级 GCC 支持C++11 或 configure: error: *** A compiler with support for C++11 language features is required.

    configure: error: *** A compiler with support for C++11 language features is required. 参考链接: (1)升级 G ...

  2. Boost Replaceable by C++11 language features or libraries

    Replaceable by C++11 language features or libraries Foreach → Range-based for Functional/Forward → P ...

  3. Quartz Tutorial 11 - Miscellaneous Features of Quartz

    文章目录 Plug-Ins Quartz提供了一个接口(org.quartz.spi.SchedulerPlugin) 用于插入附加的功能. 与Quartz一同发布的,提供了各种实用功能的插件可以在o ...

  4. Java 11 New Features

    前言 北京时间 2018年9 月 26 日,Oracle 官方宣布 Java 11 正式发布.这是 Java 大版本周期变化后的第一个长期支持版本,非常值得关注.从官网即可下载, 最新发布的 Java ...

  5. C++11 并发指南一(C++11 多线程初探)

    引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...

  6. C++11 并发指南一(C++11 多线程初探)(转)

    引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...

  7. 【C/C++开发】C++11 并发指南一(C++11 多线程初探)

    引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...

  8. Java Concurrency - java.util.concurrent API Class Diagram

    摘自: www.uml-diagrams.org Here we provide several UML class diagrams for the Java™ 7 java.util.concur ...

  9. c++11 on Android

    C++11 on Android The latest Andoird NDK r8e finally supports some of the most important C++11 librar ...

随机推荐

  1. Mybatis全部查询遇到的返回类型的小问题

    在学习Mybatis3过程中遇到一个小问题,觉得需要注意就把它写下来了 在查询所有数据的时候方法是这样的 public List<User> findAll(){ ..... } 在它的u ...

  2. jdbc的通讯录CRUD

    基于JDBC的通讯录练手:项目以MVC模式开发,包名:cn.itcast.txl.domain;cn.itcast.txl.dao;cn.itcast.txl.dao.impl;cn.itcast.t ...

  3. 企业用户2T(含秒传),普通用户20G

    周鸿祎一定要看的建议(要求置顶):可以解决本次云盘事件的建议!!! 2016-10-23 20:23 | 复制链接 | 淘帖 461334 本帖最后由 cqthxin 于 2016-10-23 20: ...

  4. Android:界面设计工具DroidDraw

    DroidDraw是款强大的安卓界面设计软件,基于Java Swing开发,可以通过它拖动控件.设置层属性.设置颜色等步骤轻松地生成复杂的安卓XML布局文件. >>>>> ...

  5. 对象的继承关系在数据库中的实现方式和PowerDesigner设计

    原文:对象的继承关系在数据库中的实现方式和PowerDesigner设计 在面向对象的编程中,使用对象的继承是一个非常普遍的做法,但是在关系数据库管理系统RDBMS中,使用的是外键表示实体(表)之间的 ...

  6. ConcurrentHashMap使用示例

    ConcurrentHashMap使用示例 发表于2年前(2013-07-12 19:05)   阅读(3660) | 评论(0) 25人收藏此文章, 我要收藏 赞5 如何快速提高你的薪资?-实力拍“ ...

  7. TCP protocol

    he characteristics of TCP protocol TCP (which means Transmission Control Protocol) is one of the mai ...

  8. android4.4内核移植

    01 init/目录下Kconfig修改: 956行添加: config PANIC_TIMEOUT int "Default panic timeout" help Set de ...

  9. ubuntu10.04开启root登陆

    半年没有用ubuntu了,以前用的是8.10,现在装了一个10.04,第一印象就是登陆窗口变了,哎,比较喜欢用root用户登录系统,不喜欢非root用户,做任何事都要来一下sudo,10.04的登陆窗 ...

  10. 定制IE浏览器的尖兵利器 - BHO

    IE浏览器是当前使用人数最广的浏览器, 本文主要来讲述如何来打造我们自己特色的浏览器, 自定义工具栏按钮, 自定义网页的右击菜单, BHO技术与IE浏览器. 本文写作过程中参考不少网络上的相关资料, ...