Q:

perl Coro shared array

I kind of newb in programming, and now little bit confused (well pretty much) about a simple task - share an array between coro coroutines. 
Something like this (not working, just takes 40 secs to do)... 
my @array = (1..1000);
$|=0;

sub start_thread($) {
    my $url = shift;
    return async {
        print "starting  $array[0]\n";
        shift @array;
        sleep(2);
      };
}

sub main{
  start_thread $_ for (1..20);
  EV::loop;
}

main;

I have read about IPC::Sharelite, and IPC::Share and tried some stuff, but nothing working... 
If somebody can clearly point me out please? 

A:

Coro is a co-operative multitasking system. That means that only one task can run at a time, and it's up to you to let other tasks run by using the event system (e.g. $cv->recv) rather than blocking calls (e.g. sleep).
use AE   qw( );
use Coro qw( async );

sub ae_sleep {
   my ($secs) = @_;
   my $cv = AE::cv();
   my $guard = AE::timer($secs, 0, $cv);
   $cv->recv();
}

sub worker {
   my ($job) = @_;
   my $id = sprintf("Thread %d: Job %s", $Coro::current, $job);
   print("$id: Running...\n");
   ae_sleep(2);
   print("$id: done.\n");
}

{
   my @array = 1..60;

   my @threads;
   for (1..20) {
      push @threads, async {
         while (defined(my $job = shift(@array))) {
            worker($job);
         }
      };
   }

   $_->join() for @threads;
}

If you use Coro::Channel instead of an array, you can add elements to the queue after you start your workers.
use AE            qw( );
use Coro          qw( async );
use Coro::Channel qw( );

sub ae_sleep { ... }  # Same as above

sub worker { ... }  # Same as above

{
   my $q = Coro::Channel->new();

   my @threads;
   for (1..20) {
      push @threads, async {
         while (defined(my $job = $q->get())) {
            worker($job);
         }
      };
   }

   $q->put($_) for 1..60;

   $q->shutdown();
   $_->join() for @threads;
}

If you wanted to use real threads, it's simply:
use threads;
use Thread::Queue qw( );  # 3.01+

sub worker {
   my ($job) = @_;
   my $id = sprintf("Thread %d: Job %s", threads->tid, $job);
   print("$id: Running...\n");
   sleep(2);
   print("$id: done.\n");
}

{
   my $q = Thread::Queue->new();

   my @threads;
   for (1..20) {
      push @threads, async {
         while (defined(my $job = $q->dequeue())) {
            worker($job);
         }
      };
   }

   $q->enqueue($_) for 1..60;

   $q->end();
   $_->join() for @threads;
}

