-
Notifications
You must be signed in to change notification settings - Fork 780
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
Issue 315: making cereal thread safe #320
Conversation
Looks good at first glance, I'll try and test this out and merge asap. Do you think these are the only two places we need to add a mutex? I'll look around myself when I go to merge this. |
I'm thinking of moving the mutex locking over to the It may be the case that this causes some extra locks, mostly when cereal is doing its initial set-up, but it catches all potential shared accesses in a clean way that doesn't involve any thought when writing future code for cereal. Another change I'm going to make is to also add your preprocessor definition to |
I'm not sure this is possible as this would only guard the creation and returning of the object, but would not prevent two threads changing the same instance of a StaticObject. |
You're correct. Only thing I'm debating is whether it would look nicer to have an interface that would allow something like auto lock = StaticObject<InputBindingMap<Archive>>::lock(); versus the need to have a lot of |
Yes, that's a lot better. |
Try out develop and let me know how this works out. I added some tests to try and capture the threading but I don't know if they do a good job; I wasn't able to create any errors with them. |
Works for me. 👍 |
I've found two place which manipulate static objects in an unsafe manner:
Versions::find()
in helpers.hppPolymorphicVirtualCaster()
in polymorphic_impl.hppThese are now guarded by
std::unique_lock
andstd::mutex
. These guards are enabled with the new compile define CEREAL_THREAD_SAFE or the cmake define THREAD_SAFE (default off to maintain backwards compatibility)