#include <vector>
#include <thread>
#include <stdlib.h>
#include <iostream>
#include <cstdint>
//#define numEntries 100
class CAS
{
private:
std::vector <std::thread> threads;
long tagIndex,arg_tag;
public:
struct vtable
{
long tag;
};
std::vector<vtable> vt;
CAS(int numEntries)
{
vt.resize(numEntries);
}
void pSearch(int i)
{
int a=10;
//unsigned i= *((unsigned *)thInd);
//if(arg_tag==vt[i].tag)
//tagIndex=i;
}
void CAS_threadEND(int i)
{
threads[i].join();
}
void parallelSearchINIT(unsigned numEntries, int _tag)
{
//threads.resize(numEntries);
for(unsigned i=0;i<numEntries;i++)
{
arg_tag=_tag;
threads.push_back(std::thread (CAS::pSearch,i));
// t;
//(void (A::*)(int)) &A::pSearch
}
}
};
int main()
{
int _tag=11;
unsigned numEntries=100;
CAS c(numEntries);
c.parallelSearchINIT(numEntries,_tag);
for(unsigned i=0;i<numEntries;i++)
c.CAS_threadEND(i);
}
I am receiving the following error at the thread creation line:
suryakalpo@suryakalpo-Lenovo-IdeaPad-Z510:~/Documents/gem5$ g++ - std=c++11 -pthread cas1.cc
cas1.cc: In member function ‘void CAS::parallelSearchINIT(unsigned int, int)’:
cas1.cc:50:48: error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, unsigned int&)’
threads.push_back(std::thread (CAS::pSearch,i));
^
cas1.cc:50:48: note: candidates are:
In file included from cas1.cc:2:0:
/usr/include/c++/4.8/thread:133:7: note: std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (CAS::*)(int); _Args = {unsigned int&}]
thread(_Callable&& __f, _Args&&... __args)
^
/usr/include/c++/4.8/thread:133:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘void (CAS::*&&)(int)’
/usr/include/c++/4.8/thread:128:5: note: std::thread::thread(std::thread&&)
thread(thread&& __t) noexcept
^
/usr/include/c++/4.8/thread:128:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/4.8/thread:122:5: note: std::thread::thread()
thread() noexcept = default;
^
/usr/include/c++/4.8/thread:122:5: note: candidate expects 0 arguments, 2 provided
I tried to resolve the function overloading by casting the member function: threads.push_back(std::thread ((void (CAS::*)(int)) &CAS::pSearch,i));
But that did not resolve the overloading, instead I get this:
suryakalpo@suryakalpo-Lenovo-IdeaPad-Z510:~/Documents/gem5$ g++ - std=c++11 -pthread cas1.cc
In file included from /usr/include/c++/4.8/thread:39:0,
from cas1.cc:2:
/usr/include/c++/4.8/functional: In instantiation of ‘struct std::_Bind_simple<std::_Mem_fn<void (CAS::*)(int)>(unsigned int)>’:
/usr/include/c++/4.8/thread:137:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (CAS::*)(int); _Args = {unsigned int&}]’
cas1.cc:49:70: required from here
/usr/include/c++/4.8/functional:1697:61: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (CAS::*)(int)>(unsigned int)>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/4.8/functional:1727:9: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (CAS::*)(int)>(unsigned int)>’
_M_invoke(_Index_tuple<_Indices...>)
Can someone please tell me why is there a case of function overloading ? Because I honestly cannot determine the source of the overloading. Moreover, is it a case of overloading for the member function of class CAS or for the constructor of class thread ?
Aucun commentaire:
Enregistrer un commentaire