Add -pthread and remove -lpthread.

-pthread introduces -lpthread and -D_REENTRANT.
-D_REENTRANT is required for safety.
Merge pull request #830 from gwtnb/pthread

Add -pthread.