Dear monks,

I am having a strange issue with a code snippet I have tested in quite a few different PCs and Windows distributions (mainly XP and Vista) and has worked fine until I ran it in an ASUS single-core netbook that has Windows XP service pack 3 and fails. I am thinking there is either a `mysterious` issue with the machine :-) or there has always been a bug in my code and it simply happened to work correctly in all the other machines.

What I am essentially doing is have a Tk application that lets the user follow some steps and show some messages accordingly. In two of these steps, I am making an HTTP GET using LWP::Simple to a router and from its xml-like answer I get a couple of variables I want. Because the main graphical application needs to be run in parallel with these two functions, I am using threads.

In the netbook I am having this issue, the second HTTP get function hangs without ever returning anything; the first works fine.

Thank you in advance for any suggestions!
Athanasia

Below you may find a simplified version of my code.
my $thread_die1 : shared; $thread_die1 = 0; my $thread_go1 : shared; $thread_go1 = 0; my $firstvar : shared; $firstvar = ''; my $thread1 = threads->new(\&getfirst); my $thread_die2 : shared; $thread_die2 = 0; my $thread_go2 : shared; $thread_go2 = 0; my $secondvar : shared; $secondvar = ''; my $thread2 = threads->new(\&getsecond); use Tk; use Tk::TopLevel; use utf8; use Win32; use LWP::Simple; use XML::Simple; use POSIX(":sys_wait_h"); $customfont = "verdana 8"; $mw = new MainWindow (-title => "My application"); $window_pos = "800x600+200+200"; $mw->geometry($window_pos); $mw->resizable(0,0); my $label = $mw->Label(-text => "Some text", -font=>$customfont)->plac +e(-x => 200, '-y' => 170); my $nextbutton = $mw -> Button(-text => "Next", -font => $customfont, -height => "1", -width => "15", -command =>\&allcompsscreen) -> place(-x => 520, '-y' => 420); MainLoop; sub allcompsscreen { my ($firsttxt, $secondtxt); $mw->withdraw(); $allcomps = $mw -> Toplevel(-title => "HTTP requests"); $allcomps->geometry($window_pos); $allcomps->resizable(0,0); $allcomps->attributes(-topmost=>1); my $waitmsg1 = $allcomps->Label(-text => "Waiting for first HT +TP GET", -font=>$customfont)->place(-x => 200, '-y' => 170); $thread_go1 = 1; my $timeout = 30; $allcomps->update(); while ((!defined $firstvar or $firstvar eq '') and $timeout > 0) { sleep 1; $allcomps->update(); $timeout -=1; } $thread_go1 = 0; $waitmsg1->placeForget; if ($firstvar eq 'A') { $firsttxt = $allcomps->Label(-text => "A", -font=>$custo +mfont)->place(-x => 200, '-y' => 170); } else { $firsttxt = $allcomps->Label(-text => "NOT A", -font=>$c +ustomfont)->place(-x => 200, '-y' => 170); } $allcomps->update; sleep 10; my $waitmsg2 = $allcomps->Label(-text => "Waiting for second +HTTP GET", -font=>$customfont)->place(-x => 200, '-y' => 270); $thread_go2 = 1; $timeout = 30; $allcomps->update(); while ((!defined $secondvar or $secondvar eq '') and $timeout > 0) + { sleep 1; $allcomps->update(); $timeout -=1; } $thread_go2 = 0; $waitmsg2->placeForget; if ($secondvar eq 'B') { $secondtxt = $allcomps->Label(-text => "B", -font=>$cust +omfont)->place(-x => 200, '-y' => 270); } else { my $secondtxt = $allcomps->Label(-text => "NOT B", -font +=>$customfont)->place(-x => 200, '-y' => 270); } $thread_die1 = 1; $thread_die2 = 1; } sub getfirst { my $url = "http://192.168.1.254/..."; while(1) { if ($thread_go1 == 1) { $firstvar = &firsthttpget($url); } else { sleep 1; } if ($thread_die1 == 1) { return; } } } sub getsecond { my $url = "http://192.168.1.254/..."; while(1) { if ($thread_go2 == 1) { $secondvar = &secondhttpget($url); } else { sleep 1; } if ($thread_die2 == 1) { return; } } } sub firsthttpget() { my $res; my $address = $_[0]; my $xmlobj = new XML::Simple; $address =~s/http:\/\//http:\/\/admin:admin\@/g; my $httpcontent = get $address; if (!defined $httpcontent or $httpcontent eq '') { $res = -1; } else { $res= $xmlobj->XMLin($httpcontent); } return $res; } sub secondhttpget { my $res; my $address = $_[0]; my $xmlobj = new XML::Simple; $address =~s/http:\/\//http:\/\/admin:admin\@/g; my $httpcontent = get $address; #Here the program hangs indefinite +ly if (!defined $httpcontent or $httpcontent eq '') { $res = -1; } else { $res = $xmlobj->XMLin($httpcontent); } return $res; }

In reply to Threads and LWP get issue in Windows by athanasia

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.