[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lfs (CVS version) compilation error under Ununtu-9.04 Jaunty
- From: Fabio Mascarenhas <mascarenhas@...>
- Date: Fri, 3 Jul 2009 13:07:45 -0300
On Fri, Jul 3, 2009 at 9:14 AM, David Given <firstname.lastname@example.org>
-----BEGIN PGP SIGNED MESSAGE-----
Fabio Mascarenhas wrote:
> Obviously I am not married to this solution, so if you have a suggestionWe did this at work. On Unix our solution was to create a dummy file and
> on how to implement exclusive locks that works both inside the same
> process (even in the same thread) and across processes, for both POSIX
> and Windows, I am all ears. :-)
then use advisory locks with fcntl(_, F_SETLKW, _) locking across the
whole file. These have the nice behaviour of being automatically
unlocked if the app terminates unexpectedly. Allegedly these even work
across NFS these days.
I thought about using file-level locks (lfs already has those), but they do let the process that acquired the lock acquire it again, which is quite common if you are using coroutines for cooperative threading (using the Xavante web server, for example). Lockfiles don't have this problem.
For Windows we used named semaphores --- there's an atomic
lookup-by-name-or-create-if-not-found function call. Then you just use
them like an ordinary mutex.
I haven't tested, but mutexes probably have the same problem as above. In Windows I use a call to CreateFile that always fails if the file already exists, and set the file to be automatically deleted when its fd is closed (or the process is killed).
If you want to lock *between* Windows and a Posix subsystem? Pass, I'm