From the course: Complete Guide to Parallel and Concurrent Programming with C++
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Starvation - C++ Tutorial
From the course: Complete Guide to Parallel and Concurrent Programming with C++
Starvation
- It would be nice if Olivia and I took turns acquiring and releasing the pair of chopsticks so we could each take an equal amount of sushi from the shared plate. But that's not guaranteed to happen. The operating system decides when each of our threads get scheduled to execute, and depending on the timing of that, it can lead to problems. If Olivia puts down the chopsticks to release her lock on the critical section, but my thread doesn't get a chance to acquire them before she takes them again, then I'll be stuck waiting again until she takes another piece. If that happens occasionally, it's probably not a big deal, but if it happens regularly, - Too slow. - then my thread's going to starve. Starvation occurs when a thread is unable to gain access to a necessary resource and is therefore unable to make progress. If another greedy thread is frequently holding a lock on the shared resource, then the starved thread won't get a chance to execute. - In a simple scenario like ours, with…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.