Fixing locking of shared resources.
Fixing matrix indexing in qs thresh.