linux-sysprog · intermediate · ~15 min

Bounded buffer occupancy

Model a bounded producer/consumer queue.

Challenge

A bounded buffer of capacity cap processes 'p' (produce, ignored if full) and 'c' (consume, ignored if empty). Implement int buffer_after(const char *ops, int cap) returning the item count at the end.

Starter code

int buffer_after(const char *ops, int cap) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.