Guarded Suspension

Learn about another concurrent design pattern called guarded suspension.

We'll cover the following

Introduction

The guarded suspension design pattern is applied to the thread in concurrent programming that requires both lock and a precondition. There will be a precondition that needs to be met before acquiring a resource, and hence this precondition will act as a guard for the lock. The method call will be suspended inside the class, and the lock can’t be acquired unless the precondition is met. The thread will be waiting unless the condition is met.

Implementations

The guarded suspension comes in several variations, which are discussed below.

The waiting thread is passively informed about the state change. It can be done using condition variables or futures.

Get hands-on with 1200+ tech skills courses.