Added support for multithreading (very basic)

Thread safety not yet implemented, and other things such as GL contexts
are causing issues if GL calls are used from other threads.