Fix ofThread destructor behaviour

The way ofThread's destructor worked was causing cleanup code at the end of threadedFunction to be skipped, sometimes leaving shared resources in an unusable state. This patch makes sure that the ofThread destructor waits until the thread has properly exited. 

IMO this patch is critical, but it should be treated with caution, as this has the possibility to cause deadlocks in code with multiple threads where the cleanup order is not clearly defined.