> To solve all three problems, I'd suggest
>
> - unconditional taking of the flock(LOCK_EX) in ps_files_open(), while
keeping
> the LOCK_UN in PS_READ_FUNC/PS_WRITE_FUNC (if minimize_lock=true).
Clarification: unconditionally in case of minimize_lock=true means taking
the LOCK_EX after the huge if, right at the end of ps_files_open, i.e. even
when data->fd was already >= 0. Otherwise the write case would miss the
lock.
If that seems strange in ps_files_open then the LOCK_EX could be placed in
PS_READ_FUNC and PS_WRITE_FUNC directly after successful call to
ps_files_open - doing it that way would have the advantage of making a
local code review in each of the functions self-contained wrt the locking.
best regards
Patrick