我正在尝试将 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/