ananonymous:

You've already gotten a few responses, but I can't keep from adding a couple things ;^)

For the question "is there time to insert another event?", I'd take a look at how much time is consumed in total:

$ cat pogo.pl #!/usr/bin/perl use strict; use warnings; use Number::Fraction; my %tasks = ( a=>4, b=>4, c=>4, d=>24, e=>24, f=>24, g=>100, h=>150, i=>150, j=> +150, k=>600 ); my $time = 0; for my $k (sort keys %tasks) { my $time_used = Number::Fraction->new( 1, $tasks{$k}); $time = $time + $time_used; print $time->to_string(), "\n"; } $ ./pogo.pl 1/4 1/2 3/4 19/24 5/6 7/8 177/200 107/120 539/600 181/200 68/75

So you definitely have time for 7 one-second events every 75 seconds, or 14 every 150 seconds, etc. Play with the factors, and you can figure out what's available.

Next comes the task of arranging them. Your task is perhaps a bit too "clean and academic" sounding. In your case, you can play with the factors and write a program to schedule all of them.

Back in a former life, when I did real-time systems, we'd just keep the tasks in a priority queue (implemented as a heap). Then, as we'd have time, we'd just pick off the next ready task. It's pretty simple, and a bit more flexible when your tasks have: (a) variable run times, and (b) a range of acceptable execution intervals. After you execute the task, just add its minimum interval to the current time and requeue it. When you pick off a task whose maximum interval has already been exceeded, generate a fault.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Time Allotments by roboticus
in thread Time Allotments by alanonymous

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.