Cleanup pthread code for data layers

Get rid of the ugly "friend" thread function. Simplify the creation of the
thread by inheriting from a base class. Thus, defining the thread is as
simple as overriding a virtual function.