views:

130

answers:

1

I have a .NET system where I need to allow files to be locked and unlocked across process boundaries. The model I plan to use is this:

  1. User generate a lock token
  2. Uses Locks a file with token and refreshes token
  3. repeat at #2 as needed
  4. Uses unlocks all files by releasing token
  5. If uses fails to refresh token in some time-frame, #4 happens automatically

Each step can be done from a different process.

The question is two fold: is this a reasonable model and are there any readily available tools for implementing it? If this can't be directly done in the OS, I'm thinking of some sort of advisory locking with .files or the like.

Edit: this mode gets non-exclusive read locks, but other modes could get exclusive write locks but they would always be released by the same process that got them.

+1  A: 

I think this SO thread might answer it for you.

JP Alioto
That doesn't cover the lock in one process, unlock in another issue.
BCS
Named Mutexes and Semaphores can signal across processes.
JP Alioto
"The Mutex class enforces thread identity, so a mutex can be released only by the thread that acquired it." and "If a thread terminates while owning a mutex, the mutex is said to be abandoned. The state of the mutex is set to signaled, and the next waiting thread gets ownership."
BCS
I'm not needing to signal cross process. I need them the *exist* cross process; as in Process A create a lock and then terminates. Then process B start up and frees the lock.
BCS
Fair enough. I guess I don't understand your architecture. If a process holding a lock ends (or dies) it will release the lock automatically, there is no need to release it on the second process. But, if you want to do what your talking about, you need an external store to all the processes -- like a database. If you had a DB with a lock table you could use it to persist lock statuses across processes and across process death.
JP Alioto
After further study, I /think/ the process will persist but I'm not so sure about the thread.
BCS
see this new question: http://stackoverflow.com/questions/827323
BCS