Bug fixes of pthread specific

Bug fixes of the pthread specific and a test added.