C++_win32 : pthread_self() == pthread_t leading to error

标签 c++ windows pthreads

我正在尝试将 linux 工作应用程序移植到 windows(使用 windows.h 和 POSIX pthread_win32)

因此,我定义了一个客户字段:

struct ClientIdentifier {
  pthread_t thread;
  int id_client;
  ...
};

vector<ClientIdentifier> clients;

我正在尝试在客户领域(返回字段索引)中找到该客户的线程

int Server::getClientIndex() {
  for (unsigned int i = 0; i < clients.size(); ++i) {
    if (pthread_self() == clients.at(i).thread) {
      return i;
    }
  }
  return -1;
}

但是这个:

pthread_self() == clients.at(i).thread

结果:

34 D:\WORKSPACE\C++\DS\gs\server.cpp no match for 'operator==' in 'pthread_self() == (((std::vector<ClientIdentifier, std::allocator<ClientIdentifier> >*)((Server*)this)) + 8u)->std::vector<_Tp, _Alloc>::at [with _Tp = ClientIdentifier, _Alloc = std::allocator<ClientIdentifier>](i)->ClientIdentifier::thread' 

note C:\programy\DevCpp\include\objbase.h:80 candidates are: BOOL operator==(const GUID&, const GUID&)

我该如何解决?

最佳答案

使用pthread_equal()比较 pthread_t 值。

关于C++_win32 : pthread_self() == pthread_t leading to error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13376583/

相关文章:

c++ - OpenCV:自定义区域/图像作为 GrabCut 的 "background"的来源

python - Python 的 Colorama,在 Windows 上不返回彩色打印线

c - Pthread 中的信号处理

c++ - HANDLE 类似于 Linux 中的文件描述符吗?

.net - fatal error C1083 : Cannot open include file: 'vld.h' : No such file or directory

c++ - 从源代码中删除 C++ 注释

windows - 如何在 Windows 7 上注册自定义程序来处理 mailto 协议(protocol)

windows - 在 Windows 上更改 .gitconfig 位置

c - 警告 : passing argument 1 of ‘pthread_join’ makes integer from pointer without a cast error

c - 更好地锁定共享资源,或者有一个线程来完成请求?