[threads] problem with subroutine lock

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I want a subroutine Lock. I tried use attrs qw(locked); but i didnt
work, all thread run into the sub. Now I tried to use semaphores
instead like this;

#!/usr/bin/perl -w

use Thread;
use Thread::Semaphore;

$sem = Thread::Semaphore->new();

sub dprint {
my $param = shift;
    print("Thread $param started\n");
    print("Thread $param ends\n");

$thread1 = new Thread \&dprint, t1;
$thread2 = new Thread \&dprint, t2;


I want
thread1 started
thread1 ends
thread2 started
thread2 ends

But i alway get
thread1 started
thread2 started
thread1 ends
thread2 ends

What is wrong here?

Site Timeline