Fix a race condition in the sorter code.
Add test file sort4.test, containing brute force tests for the multi-theaded sorter.