impl of thread, thread_lock, thread_event, tls, refbase, neat macros