Replies: 1 comment 1 reply
-
|
Yes. You'll need to lock the figure to make the operation thread-safe. Making the figure thread-safe by default is a bad idea here. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Thank you for this wonderful library!
I was playing with it to plot around 5.3 MB of data and tried plotting gantt chart like stuff using
rectanglebut because the data is too much I had to make it multithreaded. It's not possible for me to share the code and data but it looks something like this.std::mutex mut; auto do_work = [&](decltype(cpu_cnt) cnt) { for (auto const [id, st, dt] : cnt) { const std::lock_guard<std::mutex> lock(mut); auto r2 = rectangle(st, 4, dt, height); r2->fill(true); r2->color({0.4f, 0.f, 0.4f, 1.0f}); // hold(on); } }; int parts = cpu_cnt.size() / 8; for (int i = 0; i < 8; i++) { if ((i + 1) * parts < cpu_cnt.size()) { auto part = decltype(cpu_cnt)(cpu_cnt.begin() + i * parts, cpu_cnt.begin() + (i + 1) * parts); vec_threads.push_back(std::thread(do_work, part)); } else { auto part = decltype(cpu_cnt)(cpu_cnt.begin() + i * parts, cpu_cnt.end()); vec_threads.push_back(std::thread(do_work, part)); } } grid(on); hold(off); axis(tight); if (argv[3] != nullptr) save(argv[3]); else save("Temp.png"); for (auto &thread : vec_threads) { thread.join(); }Without the lock guard inside the plot it just fails. Is there any better way to plot?
Thanks again!
Beta Was this translation helpful? Give feedback.
All reactions