突然觉得写博客是个好习惯 踩过的坑都不能忘了。。
1.首先 C++创建多线程的几种方式:
C++多线程之_beginthread
https://blog.youkuaiyun.com/u013043408/article/details/83830181
C++多线程之CreateThread
https://blog.youkuaiyun.com/u013043408/article/details/83830598
C++多线程之std::thread
https://blog.youkuaiyun.com/u013043408/article/details/838555651
std::thread是C++11中新支持的多线程库,常见的创建线程、join、detach都能支持。
2.在网络模块,之前一直使用_beginthread的方式创建新线程,没有出现过问题。昨天说试一下std::thread中的thread类。
#include <thread>
仅仅是包含了thread头文件后,socket就接收不到数据了。
while

在尝试使用C++11的std::thread替换_C++的其他多线程方法后,遇到socket通信故障。问题在于当包含<std::thread>头文件后,bind函数默认调用了std命名空间中的bind,而非网络编程所需的bind。这导致UDP通信的socket无法接收到数据。解决方案是在调用bind时使用全限定名::bind,以避免命名冲突。
最低0.47元/天 解锁文章
963

被折叠的 条评论
为什么被折叠?



