No official CS education but I learned about readers-writer locks after implementing a mutex library. I happened to come across a real-world use case that I would need this for.
Say we have many people signing up to take a class, their payment (through Stripe, or whatever) might be in flight. And imagine the teacher cancels the class, which would trigger a refund event.
Without proper locking, the refund might fail to execute for those students whose payments are in flight at the time of the class cancelation.
So what we probably need to do is:
- Payments don't block each other, but they do block the cancelation/refund routine.
- Refund routine blocks all payments (and other refund routines).
That appears to be a classic readers-writer lock thing, where the payments are the readers and the refund is the writer? The only difference is that once a refund occurs, a flag is flipped never to be flipped again (no uncancellation is possible).
How can I implement an evented readers-writer lock using a relational database and multiple application servers?
Once I have more than one application server, going to have to use a lock in the database.