C++_win32: pthread_self() == pthread_t导致错误

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

本文关键字:pthread 错误 win32 self C++      更新时间:2023-10-16

我正在尝试将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:WORKSPACEC++DSgsserver.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:programyDevCppincludeobjbase.h:80 candidates are: BOOL operator==(const GUID&, const GUID&)

我该如何解决这个问题?

使用 pthread_equal() 比较pthread_t值。