threads: one_time_init, thread_cancel.

Solution to Exercises 31-1 and Listing 32-1.