Код: Выделить всё
class CMyClass
{
public:
void TestThreadPool();
protected:
void MyMethod();
...
protected:
std::unique_ptr m_tp{};
}
Код: Выделить всё
void CMyClass::MyMethod()
{
std::this_thread::sleep_for(std::chrono::seconds(33));
TRACE("CMyClass::MyMethod\n");
}
Код: Выделить всё
void CMyClass::TestThreadPool()
{
m_tp->enqueue_r(&CMyClass::MyMethod, this);
}
Если у CMyClass будет родительский элемент:
Код: Выделить всё
class CServicePortal
{
public:
void Method1(const int duration) const;
bool Method2(const int duration) const;
int Method3(const int duration) const;
};
Код: Выделить всё
class CMyClass: public CServicePortal
...
Код: Выделить всё
void CMyClass::TestThreadPool()
{
m_tp->enqueue_r(&CMyClass::MyMethod, this); // ok
m_tp->enqueue_r(&CServicePortal::Method1, this); // error
}
P.S. Используемый пул потоков берется отсюда, но может быть использован и из любого другого пула потоков.
Подробнее здесь: https://stackoverflow.com/questions/790 ... rent-class