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 7899385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:41:17+00:00 2026-06-03T08:41:17+00:00

I’m making some tests using threads in Perl 5.10.1 but I’m having some problems.

  • 0

I’m making some tests using threads in Perl 5.10.1 but I’m having some problems. First of all I have Debian GNU/Linux squeeze/sid with 2.6.32-5-amd64 (64 bits).

This is my script

#!/usr/bin/perl -w
use strict;
use warnings;
use threads;  

sub threadProcess{
    my ($number, $counter) = @_; 
    print "Enter thread #" . $number . "\n";
    while($counter < 10){
        print "Thread #" . $number . ": " . $counter . "\n";
        $counter++;
    }
    print "Exit thread #" . $number . "\n";
}

sub main{ 
    my $counter = 0;

    my $thr1 = threads->create(\&threadProcess, 1, $counter);  
    my $thr2 = threads->create(\&threadProcess, 2, $counter); 

    my $res1 = $thr1->join();  
    my $res2 = $thr2->join(); 

    print "Bye...\n";
}

main(@ARGV);

And this is the output:

Enter thread #1
Thread #1: 0
Thread #1: 1
Thread #1: 2
Thread #1: 3
Thread #1: 4
Thread #1: 5
Thread #1: 6
Thread #1: 7
Thread #1: 8
Thread #1: 9
Exit thread #1
Enter thread #2
Thread #2: 0
Thread #2: 1
Thread #2: 2
Thread #2: 3
Thread #2: 4
Thread #2: 5
Thread #2: 6
Thread #2: 7
Thread #2: 8
Thread #2: 9
Exit thread #2
Bye...

What may be the problem? Thanks in advance!

  • 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-06-03T08:41:19+00:00Added an answer on June 3, 2026 at 8:41 am

    Nothing, except that the job of threadProcess is so short that the first thread can finish before the second thread can get initialized.

    Put a delay in your loop and you will see the threads working at the same time.

    while($counter < 10){
        print "Thread #" . $number . ": " . $counter . "\n";
        sleep 1;      # or Time::HiRes::sleep 0.25, etc.
        $counter++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.