3 ms·
I also use this pattern: https://github.com/alefore/edge/blob/master/src/concurrent/protected.h https://github.com/alefore/edge/blob/master/src/concurrent/p...
by afc 4y ago
I also use this pattern: https://github.com/alefore/edge/blob/master/src/concurrent/protected.h https://github.com/alefore/edge/blob/master/src/concurrent/p...
I added an optional template Validator parameter that can be used to double-check invariants on the protected fields.
I also declared a Protected with condition subclass. Here is one example of how I use it to implement a "barrier" of sorts (the operation instance blocks in the destructor until execution of all callables passed to "Add" has completed): https://github.com/alefore/edge/blob/master/src/concurrent/operation.h https://github.com/alefore/edge/blob/master/src/concurrent/o...
I found it slightly preferable over Abseil annotations; I think it's slightly more robust (i.e., make errors, like forgetting an annotation, less likely) and I like making this explicit in the type system.