Re:“POSIX advisory locks are broken by design”
by throwaway76543 on Tuesday July 24, 2018 @08:06PM
(#17605942)
Ah yes, I was thinking about the system call interfaces but if we start looking at libc damn near nothing was reentrant until relatively recently (the late 90s and early 00s count as recent right? ... right?)
Just take a gander at all those _r functions where an extra parameter needed to be added for reentrancy.
Re:“POSIX advisory locks are broken by design”
by kazinator on Tuesday July 24, 2018 @08:42PM
(#17606105)
Some of them turned out to be hyper-corrective duds, like readdir_r. No need for that one, since the buffer it needs can be allocated in the DIR object. You'd never want multiple threads concurrently doing readdir_r from the same DIR stream; there is no credible use case for it.
(Or, maybe, optimization? Since it can store the dirent-s directly into some space designated by the caller, eliminating a copy operation from a program that wants to retain all those dirent-s.)
Re:“POSIX advisory locks are broken by design”
by throwaway76543 on Tuesday July 24, 2018 @09:04PM
(#17606210)
Is this because, as I recall, a DIR object is opaque while a FILE is not? Allowing the former to be expanded without breaking the API?
edit: Nevermind, that shouldn't matter should it? The important thing is that they're both by reference.
Re:“POSIX advisory locks are broken by design”
by loeg on Tuesday July 24, 2018 @10:18PM
(#17606466)
FILE can be opaque. Some implementations made the (arguable) mistake of implementing e.g. fileno() as a macro that accesses FILE internals, and this means they can't change that layout without breaking libc ABI of existing programs. But you can implement all POSIX stdio FILE APIs with an opaque FILE.
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.
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.
Re:“POSIX advisory locks are broken by design”
by dfox on Wednesday July 25, 2018 @07:47AM
(#17608518)
IEEE Std 1003.1-2017 actually specifies chdir() as thread-safe (obviously in the sense that it is atomic but influences all process' threads).
It strikes me as particularly weird as there are notionally POSIX-conformant OSes that implement it in a way that is not atomic.
Re:“POSIX advisory locks are broken by design”
by JdeBP on Wednesday July 25, 2018 @12:06PM
(#17610315)
Thread safety is not the issue. The issue is that multiple threads may want multiple different working directories simultaneously, for different work items. But there is one working directory for the process. This problem is partly alleviated by the ...at() family of system calls, of course.
Re:“POSIX advisory locks are broken by design”
by mjevans on Wednesday July 25, 2018 @03:08AM
(#17607402)
It's comments like this which make me think that the state stack should be on the connection handle rather than on a worker unit... or maybe they're the same thing.
Re:“POSIX advisory locks are broken by design”
by tannhaeuser on Wednesday July 25, 2018 @12:12AM
(#17606861)
Then you don't use multithreading at all rather than conclude it's broken?
A huge area that is broken w.r.t. threading is the whole internationalization stack: setlocale and all.
What if I want to write a server such that each request is executed in a potentially different locale (because it services globally distributed users?)