Implementing threads and a priority scheduler