I've a code...i want it to fork (i'm just trying threads/semaphore) 2 threads at a time...
The code i have, spawns 2 threads only first time...i want it to happen in a loop...
Your wisdom is appreciated!
#! use strict; use warnings; use threads qw(yield); use Thread::Semaphore; my @array = qw(a b c d e f g h); my @children; my @results; my $semaphore = Thread::Semaphore->new(2); for my $i (1..5) { for my $j(1..2) { threads->create(sub{\&sub_fork(threads->tid(),@array)}); } sleep(1); threads->yield(); } sub sub_fork { my ($tid,@temp) = (shift,@_); $semaphore->down(1); my $pid = fork(); if ($pid) { push (@children, $pid); print "$tid -- Running another child process - $pid.\n"; } else { print "@array\n"; } $semaphore->up(1); # sleep (2); }
Raghu

In reply to Perl thread/semaphore by imrags

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.