Convenience library: Monitor (synchronization)


Hello everyone!

I have released Monitor - a convenience library that provides an easier way to use the combination of Mutex+Condvar. This construct is also known as Java’s synchronized() statement.

Suggestions/bug reports/contributions welcome.


Interesting, it could use some documentation though. Why is guard wrapped in an Option? Also, what about multiple condition variables?


Maybe I can improve it based on your questions.

That is an implementation thing. The reason it’s wrapped in an option is because Condvar::wait*() methods take the MutexGuard by value. Do you think it’s worth fighting the type checker to maybe get a very slight performance improvement?

Interesting question. I don’t really know how that fits in with the paradigm. Do you have a specific example in mind? In any case, based on my experience with Java (where a monitor only supports a single condvar) I can say that a single-condvar Monitor is a useful construct.


Documenting the module and the pub items with /// an //! comments is good practice. I wasn’t thinking about performance, but removing the Option or at least the unwraps would be an assurance that the implementation is sound and won’t panic. I don’t really have an use case, it seems that a single condvar is the most common.