--- /dev/null
+#ifndef _THREAD_H
+#define _THREAD_H
+
+#include <pthread.h>
+
+// A rather generic thread class with start/stop functionality.
+// NOTE: stop is somewhat racy (there's no guaranteed breakout from syscalls),
+// since signals don't stick. We'll need to figure out something more
+// intelligent later, probably based on sending a signal to an fd.
+
+class Thread {
+public:
+ void run();
+ void stop();
+
+protected:
+ // Recovers the this pointer, and calls do_work().
+ static void *do_work_thunk(void *arg);
+
+ virtual void do_work() = 0;
+
+ volatile bool should_stop;
+
+private:
+ pthread_t worker_thread;
+};
+
+#endif // !defined(_THREAD_H)