flock()
is generally async-signal-safe because it is a system call. Its semantics make it hard to implement it differently. It is not in the POSIX's list of async-signal-safe functions because it is not in POSIX at all.
Is it possible to use flock()
in the sigaction handler without problems?
flock()
doesn't give any direct help. There's no reason to supposeflock()
messes with user-space structures, so there's every reason to think it will be async-signal-safe, but that's not conclusive. Thefcntl()
function, which is the POSIX locking system call, is async-signal-safe, which supports the view thatflock()
can be implemented so it is async-signal-safe, but that's still not proof. Maybe you should upgrade to usefcntl()
instead, and then you'll know you're safe. – Haileyflock()
to lock andfcntl()
to unlock? – Tidelandfcntl()
to unlock what you locked withflock()
. – Hailey