use SNMP; use Net::MAC; my $ip_address : shared= ""; my $pool : shared = 0; my $nthreads = 10; # Number of threads in pool #### foreach (1..$nthreads) { threads->create(\&getIP); } #### foreach $ip (@ip_addresses) { $ip_address = $ip; if ($pool==0) { print "Main thread has no service threads available, yielding\n"; threads->yield until $pool>0; } print "Main thread has $pool service threads available\n"; # signal that a new line is ready { lock $pool; cond_signal $pool; } print "Main thread sent signal, waiting to be signaled\n"; # wait for whichever thread wakes up to signal us { lock $ip_address; cond_wait $ip_address; } print "Main thread received signal, reading next line\n"; } #### sub getIP { while (1) { print "Thread ",$self->tid," waiting\n"; { lock $pool; $pool++; print "Pool incrementada : $pool\n"; cond_wait $pool; #all threads wait here for signal $pool--; print "Pool decrementadas : $pool \n"; } # Here i get the ip address my $t_ip = $ip_address; sleep 1; # now let's tell main that we already have the ip address print "Thread ",$self->tid," retrieved data, signaling main\n"; { lock ($ip_address); cond_signal ($ip_address); } #now i do the snmp session in the thread plus a snmpget my $sess = new SNMP::Session (DestHost => $t_ip, Community => ..., Version => '2c', UseSprintValue => '1') or die "couldn't open a session"; #The oid my $itens = new SNMP::VarList(['sometextthing', $oid]) or die "couldn't create a varlist"; $info = $sess->get($itens) or die "couldn't get info"; ... } }