3 ms·
FWIW, the tests show that sprintf_l is no faster than sprintf, if you're passing around the same locale object in different threads. So it can help, but it's no
by mort96 5y ago
FWIW, the tests show that sprintf_l is no faster than sprintf, if you're passing around the same locale object in different threads. So it can help, but it's not an automatic win unless you make sure that each thread keeps a separate locale object.
- nicoburns 5y agoDo you understand why the locale object needs to be locked? I would have expected it to be immutable...
- Akronymus 5y agoI assume that its made to be mutable to enable one to change the locale at one point and update it application wide.
- gumby 5y agoSomeone could allow users to change locale via an application's interface.
- rocqua 5y agoWhat about that requires a lock? To prevent reading a half destroyed object? Why not a write lock that allows multiple concurrent readers?
- gumby 5y agoThe whole thing is a botch. Sadly, his happens time to time in many standards. More in software than hardware standards in my experience — I wonder why.
- thayne 5y agoThere are a lot of things in c one would expect to be immutable or re-entrant that aren't.
- oefrha 5y agoThe point is if you make sprintf locale-unaware, then your locale-independent calls like sprintf("hello %s", "world") won't be affected by all the locale-locking nonsense that is causing the scaling issue. That's the "win". sprintf_l can be as slow as before if you pass in the same global locale object.
- munch117 5y agoDoesn't matter. It's fine for _l functions to be slower, because that's for information being formatted for display, which is inherently low-volume. What matters is to make the non-_l functions faster and more predictable, which is what you achieve by taking locale out of the equation.