Ensure that -lpthread is statically linked under MinGW.

(manually cherry picked from commit 9d32204790dc073265db41a8ed9cad08811f1518)