Hello,
I've just started using perl threads.
I have two threads, one controls a GUI and the other is a WWW spider. The spider thread contains a loop that continuously downloads and scans HTML documents.
My problem is that when the user exits the GUI, the spider thread needs to be told to stop whatever it's doing and exit as well. This would be easy to do with signals but I'm not sure if they apply to threads.
What I currently have is a variable shared between the two threads that the GUI sets to 1 when the spider must exit. The spider checks the variable after every download to see if it should return. The problem with this is if the spider's doing a particularly massive download or in the process of timing out, it could take a phenomenal amount of time before it actually gets a chance to check if it should return, so I'm left with a dead GUI just sitting there waiting for the spider to realise it should exit.
What I'd really love is something that works just like signals, where I can deliver a signal to the spider that tells it to execute a subroutine that would make it return immediately.
Any advice?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.