Channels and message passing

R-CHAN-V4-2medium

Hand over the data

A billing service’s invoicing job reads an invoice’s line-item amounts, in cents, from stdin and sends them in batches of three over a bounded channel to a pricing worker, which sends each batch’s subtotal back over a second channel. The job prints the invoice total. Go and Rust use their standard channels; C++ has none, so the C++ program declares a small Channel class. A watchdog prints stalled if the job has not completed within 3 seconds; it measures a whole-job deadline, not lack of progress. The pricing worker models summation and session finalization with native sleeps; it calls no billing service. Inputs are integer cents with individual values and totals within signed 32-bit range. Easy/Medium use at most 60 items in this profile; Hard uses at most 600. The supplied reporter reads the pricing-session completion receipt after run returns; keep that check when repairing run.

What needs to change

Make sure the pricing worker adds up exactly the amounts each batch held when it was sent.

Reproduce

  1. Run the program with the sample stdin (12 line items, 199 to 1299 cents) and compare the invoice total with 8988 cents.

Acceptance criteria

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

Notes

Edit run. pricer reads the item amounts, then pauses before sending that batch’s subtotal.

The channels hold up to 100 messages; each batch contains at most three item records.

Batch is a slice of pointers to mutex-protected LineItem records; the outer slice is already copied.

Sign in to open this exercise

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

Sign in