C++11 并发指南系列(C++11 多线程初探)

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

C++11 并发指南系列

引言

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

相信 Linux 程序员都用过 Pthread, 但有了 C++11 的 std::thread 以后,你可以在语言层面编写多线程程序了,直接的好处就是多线程程序的可移植性得到了很大的提高,所以作为一名 C++ 程序员,熟悉 C++11 的多线程编程方式还是很有益处的。

如果你对 C++11 不太熟悉,建议先看看维基百科上关于 C++11 新特性的介绍,中文C++11介绍英文C++11介绍 ,另外C++之父 Bjarne Stroustrup 的关于 C++11 的 FAQ 也是必看的,我也收集了一些关于C++11的资料,供大家查阅:

资料汇

http://www.open-std.org/jtc1/sc22/wg21/

C++0x/C++11 Support in GCC:http://gcc.gnu.org/projects/cxx0x.html

What is C++0x:https://www2.research.att.com/~bs/what-is-2009.pdf

Overview of the New C++:http://www.artima.com/shop/overview_of_the_new_cpp

Overview of the New C++ (C++0x).pdf:http://ishare.iask.sina.com.cn/f/20120005.html?from=like

A Brief Look at C++0x:http://www.artima.com/cppsource/cpp0x.html

Summary of C++11 Feature Availability in gcc and MSVC:http://www.aristeia.com/C++11/C++11FeatureAvailability.htm

C++ 11: Come Closer:http://www.codeproject.com/Articles/344282/Cplusplus-11-Come-Closer

C++11 threads, locks and condition variables: http://www.codeproject.com/Articles/598695/Cplusplus11-threads-locks-and-condition-variables

Move Semantics and Perfect Forwarding in C++11:http://www.codeproject.com/Articles/397492/Move-Semantics-and-Perfect-Forwarding-in-Cplusplus

http://solarianprogrammer.com/categories/C++11/

C++11 Concurrency:http://www.baptiste-wicht.com/2012/03/cpp11-concurrency-part1-start-threads/

http://www.hpl.hp.com/personal/Hans_Boehm/misc_slides/sfacm-cleaned.pdf

http://en.cppreference.com/w/cpp/thread

http://isocpp.org/blog/2012/12/c11-a-cheat-sheet-alex-sinyakov

The Biggest Changes in C++11:http://blog.smartbear.com/c-plus-plus/the-biggest-changes-in-c11-and-why-you-should-care/

Ten C++11 Features Every C++ Developer Should Use:http://www.codeproject.com/Articles/570638/Ten-Cplusplus11-Features-Every-Cplusplus-Developer

C++11 – A Glance [part 1 of n]:http://www.codeproject.com/Articles/312029/Cplusplus11-A-Glance-part-1-of-n

C++11 – A Glance [part 2 of n]:http://www.codeproject.com/Articles/314415/Cplusplus11-A-Glance-part-2-of-n

C++11(及现代C++风格)和快速迭代式开发:http://mindhacks.cn/2012/08/27/modern-cpp-practices/

Lambda Functions in C++11 - the Definitive Guide:http://www.cprogramming.com/c++11/c++11-lambda-closures.html

Better types in C++11 - nullptr, enum classes (strongly typed enumerations) and cstdint:http://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html

Rvalue-references-and-move-semantics-in-c++11:http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html

http://www.gotw.ca/publications/index.htm

http://www.devx.com/SpecialReports/Door/38865

Multi-threading in C++0x:http://accu.org/index.php/journals/1584

C++ 0X feature summary cheat sheat:http://www.iesensor.com/blog/2011/05/31/c-0x-feature-summary-cheat-sheat/

Multithreading in C++0x part 1: Starting Threads:http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-1-starting-threads.html

http://en.cppreference.com/w/cpp/thread

http://www.cplusplus.com/reference/multithreading/

Parallelism is not concurrency: http://existentialtype.wordpress.com/2011/03/17/parallelism-is-not-concurrency/

Concurrent and Parallel Programming: http://joearms.github.io/2013/04/05/concurrent-and-parallel-programming.html

Parallelism /= Concurrency: http://ghcmutterings.wordpress.com/2009/10/06/parallelism-concurrency/

Parallelism vs. Concurrency: http://www.haskell.org/haskellwiki/Parallelism_vs._Concurrency

Concurrency is not Parallelism: http://concur.rspace.googlecode.com/hg/talk/concur.html#title-slide

Concurrency vs Parallelism - What is the difference?: http://stackoverflow.com/questions/1050222/concurrency-vs-parallelism-what-is-the-difference

Difference between concurrent programming and parallel programming:http://stackoverflow.com/questions/1897993/difference-between-concurrent-programming-and-parallel-programming?rq=1

Parallelism and concurrency need different tools: http://www.yosefk.com/blog/parallelism-and-concurrency-need-different-tools.html

好了,下面来说正题吧 ;-)

与 C++11 多线程相关的头文件

C++11 新标准中引入了四个头文件来支持多线程编程,他们分别是<atomic> ,<thread>,<mutex>,<condition_variable>和<future>。

  • <atomic>:该头文主要声明了两个类, std::atomic 和 std::atomic_flag,另外还声明了一套 C 风格的原子类型和与 C 兼容的原子操作的函数。
  • <thread>:该头文件主要声明了 std::thread 类,另外 std::this_thread 命名空间也在该头文件中。
  • <mutex>:该头文件主要声明了与互斥量(mutex)相关的类,包括 std::mutex 系列类,std::lock_guard, std::unique_lock, 以及其他的类型和函数。
  • <condition_variable>:该头文件主要声明了与条件变量相关的类,包括 std::condition_variable 和 std::condition_variable_any。
  • <future>:该头文件主要声明了 std::promise, std::package_task 两个 Provider 类,以及 std::future 和 std::shared_future 两个 Future 类,另外还有一些与之相关的类型和函数,std::async() 函数就声明在此头文件中。

C++11 并发指南系列

本系列文章主要介绍 C++11 并发编程,计划分为 9 章介绍 C++11 的并发和多线程编程,分别如下:

C++11 并发指南一(C++11 多线程初探)(本章计划 1-2 篇,已完成 1 篇)

C++11 并发指南二(std::thread 详解)(本章计划 1-2 篇,已完成 1 篇)

C++11 并发指南三(std::mutex 详解)(本章计划 1-2 篇,已完成 2 篇)

  1. C++11 并发指南三(std::mutex 详解)
  2. C++11 并发指南三(Lock 详解)

C++11 并发指南四(future 详解)(本章计划 3 篇,已完成 3 篇)

  1. C++11 并发指南四(<future> 详解一 std::promise 介绍)
  2. C++11 并发指南四(<future> 详解二 std::packaged_task 介绍)
  3. C++11 并发指南四(<future> 详解三 std::future & std::shared_future)

C++11 并发指南五(std::condition_variable 详解)(本章计划 1 篇,已完成 1 篇)

C++11 并发指南六(atomic 详解)(本章计划 4 篇,已完成 4 篇)

  1. C++11 并发指南六(atomic 类型详解一 atomic_flag 介绍)
  2. C++11 并发指南六( <atomic> 类型详解二 std::atomic )
  3. C++11 并发指南六(atomic 类型详解三 std::atomic (续))
  4. C++11 并发指南六(atomic 类型详解四 C 风格原子操作介绍)

C++11 并发指南七(C++11 内存模型)(本章计划 3-4 篇,已完成 1 篇,3 篇在草稿中)

  1. C++11 并发指南七(C++11 内存模型一:介绍)

C++11 并发指南八(杂项)(本章计划 1-2 篇,已完成 0 篇,1 篇在草稿中)

C++11 并发指南九(综合运用: C++11 多线程下生产者消费者模型详解)(本章计划 1-2 篇,已完成 1 篇)



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值