Concurrency and parallelism

R-CONC-V4-2medium

Respect the limit

A report builder downloads several files. Downloads are authored wait jobs implemented with real timer/thread sleeps, not network requests. Pending waits can overlap while setup/completion still use CPU. The historical runner has a one-CPU-time quota, not a guarantee that only one thread can execute at every instant. Stdin lists job <id> <ms> lines, a deadline <ms> line and, where there is one, a limit <n> line. The report prints the results in job order, whether the whole run met the deadline, and the most downloads inside runJob at once. Inputs are complete well-formed positive-wait jobs with unique token ids, 1–32 jobs of 50–1000 integer milliseconds, limit 1–8 where present and a positive deadline chosen to admit the target schedule as in the fixtures. For these nonempty profiles the target peak is min(limit, job count), matching the printed check; lower peak is not this target even if a loose deadline could be met. OS launch/timer jitter can affect native timings/peak; no new native timing pass is claimed. Invalid/missing commands, zero/negative durations/limits, failures/cancellation and actual connection or rate-limit enforcement are outside the supplied model. The editable counters are not adversarial enforcement.

What needs to change

The remote service accepts at most limit downloads at once. Use the available slots up to limit, preserving the target peak and deadline.

Reproduce

  1. Compile and run main.cpp with the sample stdin: six downloads, limit 2. Compare most at once.

Acceptance criteria

Your review marks · Saved in this browser. Test acceptance is tracked separately.

Notes

Edit run_all. limit is the most downloads accepted at once.

run_job updates atomic in-flight counters.

Results stay in job order.

Sign in to open this exercise

The ticket brief is public. Sign in to access the exercise. Paid exercises require Pro.

Sign in