Use write() directly rather than std::cerr. This avoids mixing logs from
different threads.