Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3348744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:34:48+00:00 2026-05-18T01:34:48+00:00

I am completely new to Perl, like absolute newbie. I am trying to develop

  • 0

I am completely new to Perl, like absolute newbie. I am trying to develop a system which reads a database and, according to the results, generates a queue which launches another script.

HERE is the source code.

Now the script works as expected, except I have noticed that it doesn’t really do the threads parallel. Whether I use 1 thread or 50 threads, the execution time is the same; 1 thread is even faster.
When I have the script display which thread did what, I see the threads don’t run at the same time, because it will do thread 1, then 2, then 3 etc.

Does anyone know what I did wrong here? Again the script itself works, just not in parallel threads.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:34:49+00:00Added an answer on May 18, 2026 at 1:34 am

    You need to learn what semaphores actually are before you start using them. You’ve explicitly told the threads not to run in parallel:

    my $s           = Thread::Semaphore->new;
    #...
    
        while ($queue_id_list->pending > 0) { 
            $s->down;
            my $info = $queue_id_list->dequeue_nb;
            if (defined($info)) {
                my @details = split(/#/, $info);
                #my $result = system("./match_name db=user_".$details[0]." id=".$details[1]); 
                # normally the script above would be launched which is a php script run in php-cli and does some database things
    
                sleep(0.1);
    
                #print "Thread: ". threads->self->tid. " - Done user: ".$details[0]. " and addressbook id: ". $details[1]."\r\n";
                #print $queue_id_list->pending."\r\n";
            }
            $s->up;
        }
    

    You’ve created a semaphore $s, which by default has a count of 1. Then in the function you’re trying to run, you call $s->down at the start — which decreases the count by 1, or blocks if the count is already <1, and $s->up at the end, which increases the count by 1.

    Once a thread calls down, no other threads will run until it calls up again.

    You should carefully read the Thread::Semaphore docs, and probably this wikipedia article on semaphores, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to AIR but what I'm trying to do feels like it
I am completely new to ruby and I inherited a ruby system for a
I am completely new to Flex. Can I realistically develop, say, a medium complex
I'm completely new to Actionscript and I'm trying to figure out if it's possible
I know something about Java but completely new to Enterprise Java. I'm trying my
I am definitely new to Perl, and please forgive me if this seem like
I'm completely new to socket programming with C#, I'm trying to get two running
Being completely new to Java EE (but not to Java itself) I'm trying to
I'm completely new to Linux and have been trying to get my (Windows built)
I am completely new to LINQ in C#/.NET. I understand that I could use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.