Add mutex to avoid concurrent writes to stdout

Signed-off-by: Stéphane Depierrepont <toorop@toorop.fr>