Is json thread-safe in writing? #3468
-
I have this code segment nlohmann::json::basic_json::value_type metadata;
....
long unsigned int gappixels=0;
long unsigned int s;
#pragma omp parallel for default(shared) private(s) reduction (+: gappixels)
for (int ids=0;ids<nsp;ids++)
{
vector<coords> & cc=origPixelsCoords[ids];
s=cc.size();
metadata["num"][ids]=s;
gappixels += s;
for (long unsigned int k=0;k<s;k++)
{
metadata["originalCoords"][ids][k]={cc[k][0],cc[k][1],cc[k][2]};
}
}
which crashes unless I comment out the Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
falbrechtskirchinger
May 4, 2022
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
pam66
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
basic_json
is at most as thread-safe as the underlying types used (std::map
,std::vector
, ...), which, for the purpose of your question, translates to not at all. Use whatever mechanisms you'd ordinarily use to prevent data races.