Added pthread check and added -lpthread to compiler flags