Multithreading for rearrangement algorithm