Skip to content
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

SBMLTransforms thread safety #232

Closed
lkeegan opened this issue May 30, 2022 · 5 comments · Fixed by #302
Closed

SBMLTransforms thread safety #232

lkeegan opened this issue May 30, 2022 · 5 comments · Fixed by #302

Comments

@lkeegan
Copy link
Contributor

lkeegan commented May 30, 2022

SBMLTransforms uses a static member variable map mValues for caching component values.

If libsbml is used from multiple threads this can cause corrupted data and/or segfaults since all the threads are using the same map, e.g. if one thread clears the map while another thread is using it (see spatial-model-editor/spatial-model-editor#786)

lkeegan added a commit to lkeegan/libsbml that referenced this issue May 30, 2022
- use a local map to store component values instead of using the static map in SBMLTransforms
- now safe to call these functions from multiple threads (see sbmlteam#232)
@fbergmann
Copy link
Member

ideally, for a non-changing model, it should suffice to compute the map only once. But this wasnt' the case as the old code always called mapComponentValues and clear later on. Would need to consult with @skeating what else we can do.

@lkeegan
Copy link
Contributor Author

lkeegan commented May 31, 2022

I think ideally there would be a map for each model, rather than a single libsbml-wide map. (Even without multiple threads and assuming the map is only computed once, if you have two different models open in libsbml wouldn't they currently both use the same mValues map, potentially getting wrong results?)

Some (maybe naive) ideas:
Could mValues be added to the model?
Or if modifying the model is not a good idea, maybe SBMLTransforms could have a separate map for each model, identified by the pointer to the model, e.g. instead of

IdValueMap mValues

something like

std::map<uintptr_t,IdValueMap> map_model_pointer_to_mValues

@fbergmann
Copy link
Member

Both approaches would work, i slightly like the latter one more. Since this map would be used / updated / replaces solely by SBMLTransforms. Why would you go with uintptr_t instead of Model*?

@lkeegan
Copy link
Contributor Author

lkeegan commented May 31, 2022

Not sure why I used a uintptr_t there - Model* would be better!

@fbergmann
Copy link
Member

I'm not sure i can get to it this week, but i can have it done by next. Thanks again for letting us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants