That depends... what would you like to do during the function is stopped? Would you just like to give another program to give a chance to get some CPU time? Or would you like to change some of the data that the function is working on?

A. There is not really an easy solution... If you just want to give some other programs some CPU time you could trigger the sleep function every so often.

B. There are two hard solutions... and both include the building of a framework or module.

The first way to make this possible is to have a global variable that is read by the function. Once the variable signals to stop, the function saves all it's data and states and saves them either in memory or to a file. The memory address of the data or the filename are returned once the function is done with. When you want to resume you just point your function to the already processed data and it's states and let it start from there

The second version would be the same idea as above but with a more professional interface: Signals. You would write a module/function with signal traps. If the stop signal is given all data and states are saved. If the resume signal is given all saved data and states are reloaded and the function starts where it stopped.

Summary: It seems that you are in for some development time. You might want to take a look at Thread::Suspend.

/oliver/


In reply to Re: complex iterator needed by neuroball
in thread complex iterator needed by japhy

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.