Threading with priority queue