Hello. It seems that I can succeed at threading off a subroutine only if I do not check to see if I succeeded at it, which makes no sense. I have to be doing something wrong but I cannot see what. Can you?

I am running on Windows XP with Active State Perl v5.16.3) built for MSWin32-x86-multi-thread.

Here is a short bit of code, with the results after the __END__ statement

use 5.14.2; use threads; use Config; $Config{useithreads} or die('Recompile Perl with threads to run this program.'); ## sub endless_loop { my $button_answer = ""; my $count = 4; while (1) { while ($count--) { # Just wait around for a bit select(undef, undef, undef, 0.25); } say ("Main " . __LINE__); $count = 4; } } ## say "Main " . __LINE__ . ": Hello"; # Create and enter an endless loop in a different thread my $thread_endless_loop = threads->create(\&endless_loop) -> detach(); if (!($thread_endless_loop)) { my $message = "Main " . __LINE__ . ": Error"; die("$message Cannot create a thread\n$!\n"); } sleep(4); say "Main " . __LINE__ . ": Good Bye"; __END__ The (correct) results of running without the check for $thread_endless +_loop is: Main 25: Hello Main 19 Main 19 Main 19 Main 19 Main 35: Good Bye The results of running with the check for $thread_endless_loop is: Main 25: Hello Main 31: Error Cannot create a thread Inappropriate I/O control operation

In reply to Threads works if not checked by mnooning

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.