Fixes for semaphores, scheduling and some exit routines.

* Semaphores were not working with priority inheritance because the
schedulers resume function was actually terminating them.
* Semaphores were decrementing the count even when they weren't
allocated
* Some initial shutdown/delete code for objects, threads and processes
so that they shut down correctly.
* Some fixes to the hashmap and the iterator to tidy them up.