finished thread code, needs debugging for segfault in heap_sort