port the threaded mainloop to our new abstract mutex/thread API