in reply to multithread and STDOUT locking

Consider re-designing the script.   You don’t need n separate threads to check the health of n servers.   If already-developed open source tools like nagios cannot already do the job you’re building a solution for, then all you really need is (most likely...) one process that uses x socket(s) to send queries to y servers at least once every z seconds.   A simple select-based strategy will multiplex the incoming responses.

Assuming that you do not simply discover that Nagios is already able to do what you want, without you actually having to write anything new, the actual design of the program that you write will become so trivial that I suspect it will not actually require multithreading at all.