_LOCK_LOCALE causes unavoidable multi-threaded contention on most basic_ostream functionality
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Various operations within locale code use _LOCK_LOCALE to take a global lock. Because most basic_ostream methods hit this locale code (e.g. via use_facet), this means that most basic_ostream operations also end up taking a global lock.
The net effect of this as we discovered in our heavily multithreaded code base is that basic_ostream is completely non performant. It doesn't matter if you carefully manage your output streams (e.g. one per thread), you end up hitting contention on this global lock across all threads.
Is there a solution to this other than avoiding basic_ostream in multi threaded code?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported contention in heavily multithreaded basic_ostream usage, focusing on the locale paths reached through use_facet and the global _LOCK_LOCALE lock. Done would require identifying a concrete change that addresses the contention without violating the C++ Standard Library requirements, supported by a regression test or benchmark.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100