Implemented thread safety in array sort