Messages in this thread | | | Date | Sun, 23 Oct 2011 14:31:37 +1100 | From | NeilBrown <> | Subject | Re: lsusd - The Linux SUSpend Daemon |
| |
On Sat, 22 Oct 2011 12:31:58 -0400 (EDT) Alan Stern <stern@rowland.harvard.edu> wrote:
> On Fri, 21 Oct 2011, Alan Stern wrote: > > > > Maybe we could do something with futexes... > > > > Not easily -- as far as I can tell, futexes enjoy relatively little > > support. In any case, they provide the same service as a mutex, which > > means you'd have to build a shared lock on top of them. > > It occurred to me that we could create a new type of special file, one > intended to help with interprocess synchronization. It would support > locking (shared or exclusive, blocking or non-blocking) and the poll > system call -- the file would appear to be ready for reading whenever a > shared lock wouldn't block and ready for writing whenever an exclusive > lock wouldn't block. Actual reads and writes wouldn't have to do > anything, although maybe someone could suggest a use for them. > > Alan Stern
Tempting... We would need a good case to get something included, but not to just experiment.
The approach that I would take would probably be to extent flock() with a new flag, e.g. LOCK_POLL. then flock(fd, LOCK_EX | LOCK_POLL)
would try to get a non-blocking exclusive lock on 'fd'. If that didn't succeed it would insert a 'block' anyway [locks_insert_block()] and arrange so that when the lock might succeeds, fd gets marked to say that 'lock' might succeed. Then POLLPRI becomes enabled and select will trigger if the fd is listed in the 'exceptfds'.
I would then extend that so that lease breaking and dnotify notifications could come through select/poll rather than as signals...
But this is probably going somewhat off-topic.
NeilBrown [unhandled content-type:application/pgp-signature] | |