How to implement a remote Monitor ?

  • Thread starter Thread starter Joannes Vermorel
  • Start date Start date
J

Joannes Vermorel

I would like to implement an MarshalByRef object similar to
System.Threading.Monitor. The interface would look like

class RemoteMonitor : MarshalByRef
{
public void Enter(object obj, Guid threadID) { ... }
public void Exit(object obj, Guid threadID) { ... }
}

Let assume that each remote Threads has its unique identifier, I would like
to be able to implement RemoteMonitor in order to have a semantic identical
to the System.Threading.Monitor. It's tricky and the only solutions I can
think of are complicated and computionally inefficient.

Does anyone has an idea?
Joannès
 
Joannes,

I would ask first why you want to do this? To allow this kind of
granular control into a system from the outside doesn't seem like very good
design.

Can you elaborate?
 
I would ask first why you want to do this? To allow this kind of
granular control into a system from the outside doesn't seem like very
good design.

Can you elaborate?

The reason lies in a transparent grid computing framework that I am working.
Look at the NGrid project on http://ngrid.sf.net (not really up to date, I
will release soon). Basically I want to implement a distributed Monitor.

Joannès
 
One question I have is does it need to be reentrant? Does an owner of the
lock need to be able to reenter the lock multiple times? If you just need
mutal exclusion, I might do a binary Semaphore with count of 1. See my
implementation at code project:
http://www.codeproject.com/csharp/DijkstraCountingSemaphore.asp

That way, you don't care what thread owns it, just that someone does. The
owner must release it when done. Other threads will block until lock free.
You need to handle situation where an owner dies and never frees the lock.
You have that issue regardess of the primitive used. You can use some
monitor thread or some timeout on lock that handles release after some X
seconds. You could also use a Mutex. That is reentrant and needs to be
released same number of times.
 
Back
Top