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

Thread safety of parse() #800

Closed
tanaynv opened this issue Oct 26, 2017 · 3 comments
Closed

Thread safety of parse() #800

tanaynv opened this issue Oct 26, 2017 · 3 comments

Comments

@tanaynv
Copy link

tanaynv commented Oct 26, 2017

Hi,

I plan to use this library to parse JSON files in a multithreaded environment. Specifically I am concerned about thread safety with respect to the behaviour of parse() when called simultaneously from different threads. I would appreciate any help or input on this matter.

Thanks,
Tanay

@nlohmann
Copy link
Owner

Internally, the library uses std::map, std::vector and std::string to store values. parse goes sequentially through the input and creates values on the fly. Calling parse from a different thread on the same json value will most likely be problematic.

Something like:

  • Thread 1: json j1 = json::parse(...);
  • Thread 2: json j2 = json::parse(...);

should be safe, because the two values j1 and j2 do not share any state.

@nlohmann
Copy link
Owner

@tanaynv Do you need any further information?

@tanaynv
Copy link
Author

tanaynv commented Oct 31, 2017

Hi Niels,
Thank you very much for your reply, it was helpful. I need no further information at this point.

@tanaynv tanaynv closed this as completed Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants