C++11对多线程的支持很完善,互斥量,锁,条件变量,原子操作一应俱全,posix线程库还能另外提供的也就是记录锁,消息队列,但这些都可以在需要时自行实现.而且用C++原生线程库的代码还能够跨平台.
请问现在实际工程中涉及多线程的部分向C++11原生多线程库迁移的如何了?使用posix线程库进行开发的情况还多不多?
黄舟2017-04-17 11:43:57
In POSIX systems, do you think you can get rid of PThread? It seems that the bottom layer is implemented by PThread. There is no problem at all simply using std::thread, but complex functions that need to be customized must be encapsulated based on PThread. STL is better at algorithms and containers, but multi-threading is not very good. Only represents personal opinion.
迷茫2017-04-17 11:43:57
I remember that the thread library of C++11 is packaged according to OpenMP. pThread is still inferior to OpenMP in terms of performance and usage. Personally, I think it can be understood. If you don't have time, there is no need to delve deeper.
阿神2017-04-17 11:43:57
I think: std::thread and so on provided by C++11 are not language-level support, but standard library support. In fact, there is no difference between c++ thread and pthread in terms of learning and usage (maybe pthread has more parameters?), and there are other things that pthread can provide as you mentioned. As for performance, I don't think there will be any difference between the two. More differences may be in portability.
So, I think we might as well learn both.