1 of the parameters to creating the thread is User Data. Pass in your class instance as the User Data.
I find that the easiest way is to call a non-static function from the static function if I need to access variables more than a few times.
m_hThread = CreateThread(NULL, 0, &ThreadProc, this, 0, NULL);
DWORD WINAPI MyClass::ThreadProc(void *pInst) {
return ((MyClass *)pInst)->ThreadProcInternal();
}
DWORD MyClass::ThreadProcInternal() {
m_nMyNumber = 0;
}
EDIT:
This example uses Win32 Threads, but the principal is the same for all thread implementations like pthreads. They all take a user defined parameter.