Passing a C++ function object to pthread_create function as the thread routine

浪尽此生 提交于 2019-12-01 09:05:24
Michael Burr

A pthread function must have C linkage, so it cannot be a member function. Strictly speaking, it cannot even be a static member function, even though that will work almost all the time.

So what should be done is to create a non-member function that takes a void* argument that will be a pointer to the C++ object to be the thread function. That function can cast the void* argument to a class pointer, which calls the member function.

See In C++, is it safe/portable to use static member function pointer for C API callbacks?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!