-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Threadsafe mojos #474
base: master
Are you sure you want to change the base?
Threadsafe mojos #474
Conversation
Use singleton holder pattern instead of double checked locking.
Use singleton holder pattern for lazy initialisation of static cache, and make the cache concurrency safe as it can be read and updated simultaneously in multi module builds.
@olamy - I've had a look at that other commit and had a look at reworking the patch I made. There is a lot of external synchronization in that commit, following the pattern for existing uses of the cached dependencies, which along with the various interpretations of the dependency map (as a cache or a project dependencies) makes it quite hard to follow and reason about. The synchronization seems to be in place to make some of the bulk cache reads/updates atomic, although that's not 100% applied across all uses. The change to a synchronized map will (I think) avoid most of the concurrent modification exceptions, but there are remaining cases where bulk reads (which iterate internally) might occur concurrently with map mutations. We can wrap this up in a couple of ways:
The first option is much more maintainable, but I can appreciate if the maintainers need to live with the code they have and can't break API, in which case I'd probably recommend the third option. |
@timw I think you can go with first option. I tried to search who use api package: and I don't see a reason to have strict I consider that it is rather a util than api - but for me is for internal use only. |
Make all Mojos threadsafe (some had already been marked as thread safe in previous work).
This primarily addresses #86, where the static artifact cache in
DefaultThirdPartyHelper
could be concurrently read/updated.This patch retains the lazy initialisation of the cache, using the singleton holder approach, and I updated the similar instantiation in
SpdxLicenseList
to use the same pattern to be consistent (instead of the double checked locking).I've reviewed the fields used by all the other mojos that are newly marked as thread-safe, and they all look OK.
Mainly this means they don't make unsafe use of statics or other potentially shared data structures (there are plenty of areas where the Mojos would not be safe for a single instance to be used on multiple threads, but the default Mojo instantiation strategy should preclude those cases)