I don't have a perfect solution, nor even a good answer for you, but I do have some observations & speculations.

The freeze occurs when attempting to create the second thread.

If you comment out the recv call in the first thread, the freeze does not occur.

What the subroutine being started in that second thread, is or does, is irrelevant.

It never reaches the point of being called, nor even the (C) thread being created.

This I believe can only mean that the OS is deferring the creation of the new thread until the recv completes.

This does not happen with normal sockets created by IO::Socket.

As the socket created by IO::Socket::Multicast *is* an IO::Socket instance, the only real difference is that the it has had

setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,(void*) &mreq,sizeof(mreq)) + < 0)

called upon it.

I suspect that the difference 'tween *nix & Windows lies in the implementation of that socket option. I also suspect that using recv on a blocking socket may be an underlying problem

This latter suspicion is "confirmed" by the following version of your code that sets the socket non-blocking which allows it to run to completion:

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=>220 +0); $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=>220 +0); $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();

Whether this can work with your application ...


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Threads and Package differences between Linux and Windows by BrowserUk
in thread Threads and Package differences between Linux and Windows by digitalhack

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.