|
|
|
|
|
by NightMKoder
2700 days ago
|
|
I haven’t heard about conditional critical regions before - here’s a interesting set of slides for others: http://www-ist.massey.ac.nz/csnotes/355/lectures/monitors.pd... . Seems very closely related to condition variables - except you specify the condition at the lock site rather than via a “trigger” before an unlock. I think Google’s internal Mutex class had a LockWhen(callback) which is a pleasure to work with. Definitely an awesome concept. |
|
To understand it better here's the solution to the producer/consumer problem (from wikipedia), using mutexes and semaphores:
and the same problem solved using CCRs: The most important thing about CCRs is that they are supposed to guarantee fairness, along with mutual exclusion. A well-designed solution uses two binary semaphore queues to achieve this.If anyone wants to see what an implementation looks like here's a small C library I wrote a while ago, to use for some of my own personal projects, and to solve some homework for Uni https://github.com/Gikoskos/libccr