package T; use strict; use threads; use IO::Socket::Multicast; our $sock = undef; sub createsock { my $create = shift @_; my $noBlock == 1; if ($create) { $sock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>2200); $sock->mcast_add('226.1.1.2') || die "Couldn't set group: $!\n"; ioctl( $sock, 0x8004667e, \$noBlock ); } } sub mysub1 { my ($sub, $msg) = shift @_; my $noBlock == 1; print "start sub $sub\n"; #my $key = getc(STDIN); my $data; if ($sock == undef) { $sock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>2200); $sock->mcast_add('226.1.1.2') || die "Couldn't set group: $!\n"; ioctl( $sock, 0x8004667e, \$noBlock ); } $sock->recv($data,1024); print "end sub $sub\n"; } sub mysub2 { my ($sub, $msg) = shift @_; print "start sub $sub\n"; print "msg from sub $sub: $msg\n"; print "end sub $sub\n"; } package main; T::createsock(1); my $t1 = threads->create( \&T::mysub1, 1, "test 1"); select(undef, undef, undef, .25); print "above mysub2\n"; my $t2 = threads->create( sub{ warn }, 2, "test 2"); print "below mysub2\n"; $t2->join();