Re:“POSIX advisory locks are broken by design”
by Dylan16807 on Wednesday July 25, 2018 @05:57PM
(#17613272)
Being unable to control a lock from multiple threads isn't a great API either. Per file descriptor^H^Hion is closer to what I'd call ideal. It gives you a locking context that can map m:n to threads. Even if it is a bit fussy with things like fseek.
I don't think it's even that. It's simply because the API describes the contract between the kernel and processes, not the kernel and threads. It's a case of determining who is responsible for what.
In this case the process is responsible for coordinating file locks with the kernel, not individual threads. From the kernel's perspective, 2 requests to the locking API from different threads still come from the same actor: the process. From the perspective of the locking API threads are a process's private business.
A developer failing to understand the abstraction levels in an API is not the fault of the API's design, but it could be caused by documentation.