Synchronize profile printing.

This avoids interleaving/garbling of profiles from multiple threads.