Search⌘ K
AI Features

Exercise: Thread-Safe Voucher Redemption

Explore how to implement thread-safe voucher redemption in C# by using a lock statement to synchronize access and Task.WhenAll to handle concurrent requests. Understand how to prevent race conditions ensuring a discount voucher is applied only once in an e-commerce scenario.

Problem statement

In an e-commerce application, a user attempts to exploit a single-use $50 discount voucher by clicking “Apply” simultaneously from their smartphone and ...