作为C ++类的成员启动线程的最佳方式? [英] Best way to start a thread as a member of a C++ class?

查看:129
本文介绍了作为C ++类的成员启动线程的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何以最好的方式启动一个属于C ++类成员的pthread?我自己的方法作为答案...

I'm wondering the best way to start a pthread that is a member of a C++ class? My own approach follows as an answer...

推荐答案

我通常使用类的静态成员函数,作为void *参数的类。然后,该函数可以执行线程处理,或者使用类引用调用另一个非静态成员函数。然后,该函数可以引用所有类成员,而不使用尴尬的语法。

I usually use a static member function of the class, and use a pointer to the class as the void * parameter. That function can then either perform thread processing, or call another non-static member function with the class reference. That function can then reference all class members without awkward syntax.

这篇关于作为C ++类的成员启动线程的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆