Log errors properly for failing pthread operations

As suggested by @kacfengine.