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.
* _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.