Threads Algorithm