-
Notifications
You must be signed in to change notification settings - Fork 565
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
Use read-write lock in Hierarchy #316
Comments
@leventov commented on Jun 14, 2018, 7:56 PM GMT+2:
Do you have any numbers from a benchmark?
I also could bump up the requirements to C++ and call it a 2.1 version or such. But without any numbers as a good argument I cannot justify it for myself. |
I have changed the mutex type on branch master-make-hashtable-mutex-rw-lock to |
I did mutex contention profiling of my application with the mutrace tool and this mutex appeared to be the most contentious one. I don't think specific numbers matter because it depends entirely on how heavily the application is calling the logger and from how many threads. In my application this was likely due to suboptimally written code, You could also use some sort of concurrent hash map. |
@leventov commented on Jun 15, 2018, 2:45 PM GMT+2:
I have pushed a changes set to aforementioned branch that splits the Logger instance retrieval to shared locked read only path and exclusive locked read-write path. Though it is not using the
Implementing concurrent hash maps is hard. |
@leventov @wilx
I suppose the problem is inside SharedMutex class, probably it relates to some work with counters, but I'm not sure. Could you please check one more time? |
I have found the root cause of problem above: if your application tries to reset the configuration by the following method, you will get a dead lock.
The mutex is locked first time inside HierarchyLocker lock, and the thread tries to lock it the second time inside PropertyConfigurator::configure(). I assume you need to update PropertyConfigurator::getLogger - replace getInstance to getInstanceImplUnlocked for example:
Also, I suggest trying the classical |
If we do this, this should go to master branch, potential 3.x release. There we can use C++20 features and drop the poor man's shared mutex in favour of standard C++ shared mutex. It would be a good reason to release 3.x. So far I have only been accumulating small tweaks compared to 2.x branches. |
Well, now that I look at it, there are more changes that are worth releasing: 2.1.x...master |
Yes, agree with you. Also, I want to mention the following thing: the problem with this code
can be resolved not by updating
So the user should determine where the lock is already set. I just want to mention that this is proper, but not obvious way, I think it will be good to check this somehow inside log4cplus or add this information to the documentation) |
Please use read-write lock, such as
std::shared_mutex
, here:log4cplus/include/log4cplus/hierarchy.h
Line 299 in 9362135
The text was updated successfully, but these errors were encountered: