Thread::Semaphore for thisprint statement with a semaphore
use Thread::Semaphore;
my $output = Thread::Semaphore->new;
# ... later
$output->down; # acquire semaphore
print "Writer: connected to $remote_ip:$remote_port\n";
$output->up; # release semaphore