fix more threading API related bugs
9 files changed