Some code cleanup.
Added proper thread signaling to Darwin threads.