P takes one, V gives one back: let at most k threads in at once, or make threads take turns.
This interactive visualization needs JavaScript.