multithreading - C++0x 线程和套接字

标签 multithreading sockets c++11 bind

我正在编写一个连接到 CAN 接口(interface)的 C++ 程序(用于 Arm 架构)。 我为此使用标准套接字、绑定(bind)、接收和发送函数。 现在我需要将一些功能外包到线程中。 为此,我想使用 C++0x 线程,因为我在这里读到,由于兼容性问题,pthreads 不应在 c++ 中使用。

所以我包括线程库 #include <thread> 。并添加到我的编译器调用选项 -Wno-psabi -std=c++0x -lpthread

( -Wno-psabi 用于禁用 note: the mangling of ‘va_list’ has changed in GCC 4.4 消息)

我得到的错误是:

25: error: no match for ‘operator<’ in ‘std::bind(_Functor, _ArgTypes ...) [with _Functor = int, _ArgTypes = sockaddr*, unsigned int](((sockaddr*)(&((can*)this)->can::addr)), 16u) < 0

/usr/arm-linux-gnueabi/include/c++/4.4.5/system_error:258: note: candidates are: bool std::operator<(const std::error_condition&, const std::error_condition&)

/usr/arm-linux-gnueabi/include/c++/4.4.5/system_error:177: note: bool std::operator<(const std::error_code&, const std::error_code&)

我认为线程库中的绑定(bind)函数覆盖了套接字中的绑定(bind)函数。

我如何告诉编译器何时使用什么函数?

我正在使用arm-linux-gnueabi-g++版本4.4.5

最佳答案

尝试对 C 函数使用 ::bind,或者不要使用 using namespace std 并完全限定您的 std 函数调用。

还有中间解决方案,参见:

关于multithreading - C++0x 线程和套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16562166/

相关文章:

multithreading - C++11 加入第一个完成的线程

java - 是否有一个 Java 线程池对象可以在可用内核之间自动对线程进行负载平衡,或者这是由 JVM 为您完成的?

ios - 没有 iOS 套接字框架可以连接到服务器套接字

java - 能够成功写入数据,但无法从服务器读取数据

c++ - 使用 auto 作为模板参数

c++ - 类 X 的配置类,它应该嵌套在 X 中还是 X 之外?

java - 为什么占用的核心数高于线程池大小?

c++ - 绑定(bind)服务器套接字时出现 WSA 错误 10048

C++11 类型特征 : Arithmetic user type

java - 为什么即使我不调用 get() 或 join() 这个 CompletableFuture 也能工作?