thread library: implemented phase 1, yet still buggy