What does it mean for folly::Synchronized object to be const?

193 views Asked by At

I want to write some utility functions that operate on Synchronized<T> objects. I could write 2 versions one for const and one for non-const but that seems silly. Alternatively I could write 1 version just for const. I'm not sure if there's any downside to this because it seems like you can still modify the "locked" object via Synchronized::wlock method.

folly::Synchronized allows calling wlock (ie lock exclusively in write mode) on both a const Synchronized and non-const Synchronized object -- link.

However they return different output types. Is there any difference between LockedPtr and ConstWLockedPtr? In particular I'm interested in differences in functionality & in particular any lack of functionality with ConstWLockedPtr.

1

There are 1 answers

1
Chris Gregory On BEST ANSWER

wlock does not compile when used on a const folly::Synchronized<T>&. So you must a mutable reference to call wlock. For rlock you can use mutable or const; it'll just implicitly convert to const.