Created
June 23, 2015 21:49
-
-
Save AlexTape/0a31c1086592e5807c3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyThreadClass | |
{ | |
public: | |
MyThreadClass() {/* empty */} | |
virtual ~MyThreadClass() {/* empty */} | |
/** Returns true if the thread was successfully started, false if there was an error starting the thread */ | |
bool StartInternalThread() | |
{ | |
return (pthread_create(&_thread, NULL, InternalThreadEntryFunc, this) == 0); | |
} | |
/** Will not return until the internal thread has exited. */ | |
void WaitForInternalThreadToExit() | |
{ | |
(void) pthread_join(_thread, NULL); | |
} | |
protected: | |
/** Implement this method in your subclass with the code you want your thread to run. */ | |
virtual void InternalThreadEntry() = 0; | |
private: | |
static void * InternalThreadEntryFunc(void * This) {((MyThreadClass *)This)->InternalThreadEntry(); return NULL;} | |
pthread_t _thread; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment