Skip to content

Const method should be thread safe #108

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

Closed
yosupo06 opened this issue Feb 20, 2021 · 2 comments
Closed

Const method should be thread safe #108

yosupo06 opened this issue Feb 20, 2021 · 2 comments

Comments

@yosupo06
Copy link
Collaborator

By #107 , we add const to some methods of lazysegtree.

But it seems that const method should be thread safe.

@hitonanode
Copy link
Contributor

Sorry for my careless PR...

It seems that one of the easiest ways to resolve this issue while maintaining const 's might be introducing std::mutex to lazy_segtree. I tried writing the simple draft version of thread safe lazy_segtree using mutex for consideration (In this implementation, the mutexes are declared as global variables. Declaring them as member variables of lazy_segtree fails the test of ACL, since copy constructor for mutex is prohibited).

Unfortunately, it seems that the huge execution time degradation occurs when Clang is used because of the overhead of mutex...

Problem Used methods Plain lazy_segtree Using mutex
AtCoder practice2-K prod(), apply() GCC, 796 ms / Clang, 865 ms GCC, 750 ms / Clang, 1842 ms

There might be a more effective way that I do not came up with to resolve this issue. At present, it seems that reverting this repo to the previous version is worth consideration (if possilble).

@yosupo06
Copy link
Collaborator Author

yosupo06 commented Mar 1, 2021

OK, we decide to revert the change of lazysegtree, so segtree has const but lazysegtree doesn't have const. Though it is a breaking change, I hope it doesn't occur any heavy problems (because it is not merged into production branch yet).

TBH, I think there is no nice solution for introduce const into lazysegtree, at least we cannot accept std::mutex... (>99.9% code of competitive programming is in single thread and std::mutex is a simply obstacle...)

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

No branches or pull requests

2 participants