Overhauled threading code; rwlocks are now recursive, and there are more consts around