complete implementation of pi_thread functions