The first thread would run fine. But the second thread would always cause a crash

I've tried running your code as-is and cannot get it to crash (over the space of a few runs) on my perl which is This is perl 5, version 20, subversion 3 (v5.20.3) built for x86_64-linux-thread-multi. To remove some possible sources of error I then made a few changes and come up with this, which I can't get to crash either.

#!/usr/bin/perl -l use strict; use warnings FATAL => 'all'; use threads; use threads::shared; use HTTP::Headers; use LWP::UserAgent; my $counter_thread : shared; sub getgoog { my $method = "GET"; my $uri = "https://www.google.com/"; my $header = HTTP::Headers->new(); $header->push_header("Content-Type" => "application/json"); my $ua = LWP::UserAgent->new; $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00); my $request = HTTP::Request->new(); $request->method($method); $request->uri($uri); $request->headers($header); my $response = $ua->request($request); print $counter_thread++, "th :", "Dumped Data Returned:\n\n ", sub +str ($response->decoded_content, 0, 256); print "Response code: ", $response->code, "\tHTTP Response Messag +e: ", $response->message, " "; print "Thread id: ", threads->tid(), "\n"; } my $thra = threads->create (\&getgoog); $thra-> join; my $thrb = threads->create (\&getgoog); $thrb-> join;

For clarity, the changes are:

What happens if you try running my code? You might also want to consider experimenting with not making warnings fatal.


In reply to Re: HTTP Request and Threads by hippo
in thread HTTP Request and Threads by banhmi

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.