News for hackers. Stuff that matters.
Re:“POSIX advisory locks are broken by design” by caf on Tuesday July 24, 2018 @08:18PM (#17605991)
What if I want to write a server such that each request is executed in a potentially different locale?

You can use uselocale() to install a thread-specific locale.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/us...

Re:“POSIX advisory locks are broken by design” by haimez on Tuesday July 24, 2018 @09:01PM (#17606203)
Then your thread better only execute one request at a time and carry through every operation involved in that request. Works fine in PHP, not fine in most performant and even most non performant web contexts.
Re:“POSIX advisory locks are broken by design” by kazinator on Tuesday July 24, 2018 @09:54PM (#17606379)
But that's fine. For example, you pull the thread from a pool and bind it to the request. As part of this, the thread pulls the locale object from the request and attaches to it. It services that request, and then returns to the pool. Next time it is pulled from the pool it gets a request in a different locale.

Other disciplines are possible. E.g. some operation involving multiple locales, all in one thread, can just do the uselocale calls as needed.

Re:“POSIX advisory locks are broken by design” by int_19h on Wednesday July 25, 2018 @03:11AM (#17607411)
That's not fine, because processing a single request often involves waiting on some I/O, and the thread can service (a part of) another request in the meantime. Which is what modern event loop driven servers do - but this doesn't play well with thread locals, or abstractions implemented on top of them, because now your single physical thread effectively runs multiple cooperatively scheduled logical threads/requests.
Re:“POSIX advisory locks are broken by design” by kazinator on Tuesday July 24, 2018 @08:37PM (#17606076)
That's useful to know; so they finally patched this, some ten years ago now.
Re:“POSIX advisory locks are broken by design” by ecnahc515 on Tuesday July 24, 2018 @09:24PM (#17606284)
haimez said this already, but I wanted to phrase it another way:

This only works if your not executing multiple requests in the same thread, ie: using non-blocking IO.

Re:“POSIX advisory locks are broken by design” by caf on Tuesday July 24, 2018 @09:41PM (#17606334)
Even if you're using non-blocking or asynchronous IO there's always going to be a point at which you switch to the context of a particular request in order to handle it, and that's the point at which you can also switch locales if you want to handle it in a locale-specific way.