当前位置: 技术问答>linux和unix
成员函数 作为 线程函数。测了一天,求解!
来源: 互联网 发布时间:2017-05-01
本文导语: 本帖最后由 shouso888 于 2013-11-07 23:16:24 编辑 class SomeClass { public: SomeClass(int static_data, int none_static_data); void TackNoneStaticThreadFunc(); private: void* NoneStaticThreadFunc(void* param...
{
public:
SomeClass(int static_data, int none_static_data);
void TackNoneStaticThreadFunc();
private:
void* NoneStaticThreadFunc(void* param);
private:
int none_static_data_;
static int static_data_;
};
TackNoneStaticThreadFunc 会开启线程调用 NoneStaticThreadFunc 作为线程函数,...
|
/*
* filename: test.cpp
*/
#include
#include
class task
{
public:
explicit task(int times) : echo_times_(times)
{
}
void active_thread()
{
pthread_t tid;
::pthread_create(&tid, NULL, task::thread_func, this);
::pthread_join(tid, NULL);
}
private:
static void* thread_func(void *param)
{
task *self = (task*)param;
for (int i = 0; i echo_times_; ++i)
std::cout