The Single Buffer Producer/Consumer Solution

This lesson fixes the problem we saw in the solution in the last lesson.

We'll cover the following

As we discussed in the last lesson, we clearly need to have directed signalling i.e. a consumer should only wake up a producer and vice versa. The solution here is once again a small one: use two condition variables, instead of one, in order to properly signal which type of thread should wake up when the state of the system changes. The code excerpt below shows the resulting code.

Get hands-on with 1200+ tech skills courses.