Implemented thread handling for WaitForMultipleObjects.

Implemented thread specific functions:
* Thread debugging (open handles, ...) now available via CMake flag
** Add DumpThreadHandles wherever you want to know the state of thread handles
* CloseHandle now properly supports threads via registered close function
* WaitForSingleObject and WaitForMultipleObjects now support threads in INFINITE and timed wait.
* WaitForMultipleObjects bWaitAll now supported
* _GetCurrentThread now actually returns a valid handle.

* Thread pool cleanup fixed, now properly cleaning up resources in ArrayList free function and exiting thread.
* pthread_mutex_timedlock now using actual timeout instead of 10ms polling.
There's a race condition on this variable if 2 threads call WaitForSingleObject() concurrently. 
pthread_join() is atomically correct with this, so we should call it inconditionaly, and we can remove this struct member too (joined).