pthread: fix two potential memory leaks
port to C11 (untested due to lack of compiler support)
pthread: wait for t to be completely initialized before calling proc fn
pthread: destroy the fake lock after using it
C11: various fixes