1
컴파일 시간 C++의 변수 유형을 결정을 일하고있다 :다음
class pool
{
private:
std::vector<int> m_buffer;
public:
void insert(int a) { m_buffer.push_back(a); }
int size() { return (int)(m_buffer.size()); }
virtual ~pool() {}
};
class customMem
{
public:
static thread_local pool poolmanager;
static boost::thread_specific_ptr< pool> poolmanager_boost;
};
thread_local pool customMem::poolmanager;
boost::thread_specific_ptr<pool> customMem::poolmanager_boost; //very slow
class MVeryLongData : public customMem
{
public:
MVeryLongData(bool localthread, int a)
{
if (localthread)
{
customMem::poolmanager.insert(a);
}
else
{
if (!customMem::poolmanager_boost.get()) {
// first time called by this thread
// construct test element to be used in all subsequent calls from this thread
customMem::poolmanager_boost.reset(new pool);
}
customMem::poolmanager_boost->insert(a);
}
}
int size() { return customMem::poolmanager.size(); }
};
void func(bool localthread)
{
#pragma omp parallel for
for (int i = 0; i < 10000000; i++)
{
MVeryLongData a(localthread, i);
}
}
어떻게 든로 기능 FUNC에 부울 localthread 제거 할 수있는 방법이 있는지 궁금하고 poolmanager_boost와 poolmanager를 병합합니다. 이 두 변수를 호출하는 이유는 thread_local이 Visual Studio C++ 12에서 완전히 지원되지 않는다는 것입니다.
가능하거나 불가능한 경우 합치십시오. 조건부 표준을 사용할 수 있습니까?
템플릿을 피하려고합니다.
EDIT : 제 질문에 대한 해결책을 찾지 못했기 때문에 템플릿을 사용하는 것 외에는 선택의 여지가 없습니다. 따라서 템플릿이있는 솔루션은으로 잘 알려져 있습니다. boost_thread_ptr 또는 thread_local 풀 *을 반환하는 getter 함수와 같은 것입니다.
이 그럼 당신은 운이 있습니다 과부하를 사용할 수 있습니다. 이것이 바로 템플릿이 필요한 것입니다. 유일한 해결책은 엉망이며 매크로가 관련되어 있습니다. – StoryTeller
많은 다른 위치에서 customMem이 사용되었으므로 템플릿을 사용하지 않습니다. 그 말은 내가 그들과 만져야한다는 것을 의미합니다. 내가 맞습니까? –
은'bool localthread' 컴파일시의 상수입니까? – StoryTeller