Re: Creating a Shared Lock



No thats not suffecient. I am writing a test application and I need to
syncronize my database access. I need one funciton to execute at the rate
around 100 times a seconds. This funcation will be called at the same time
from multiple threads. A second thread that is called once every second
needs to lock so the other function does not get called while its running.

In SQL you would do this by creating a shared lock on the first function
then a exclusive lock on the second. This allows many threads to have
shared access but once a thread has an exclusive lock any shared locks will
wait.

It sounds like the ReaderWriterLock is what I will need. I didn't even no
that class existed.


"William Stacey [MVP]" <william.stacey@xxxxxxxxx> wrote in message
news:eNKVGEeSGHA.5728@xxxxxxxxxxxxxxxxxxxxxxx
Hi Bob. That is actually what a Monitor if for. Only one thead at a time
can own the lock on the Monitor object and any others will Q waiting for
it
to free in ~FIFO order. Each thread must lock on the same object for this
to work.

--
William Stacey [MVP]

"Bob Bins" <msgdev@xxxxxxxxxxx> wrote in message
news:%23ZkNlhdSGHA.5900@xxxxxxxxxxxxxxxxxxxxxxx
| Is there a way to create a shared lock using the Monitor class or any
other
| synchronization class in .NET?
|
| So I have one resource that may have multiple threads using it at once
but
a
| second thread that when called must have exclusive access and cause the
| other threads to wait.
|
| I can't figure out how to do this with .Net.
|
| Thanks.
|
|




.



Relevant Pages

  • flock incorrectly detects deadlock on 7-stable and current
    ... exclusive lock but fails with a deadlock avoided. ... Process 1 requests and gets a shared lock ... Process 2 requests and blocks for an exclusive lock ...
    (freebsd-stable)
  • Re: Ensuring that a thread doesnt own a critical section within a function
    ... fix is to specify that 'f' cannot be called while holding the lock. ... purpose of the 'f' function is to wait for the second thread to change ... The purpose of the lock is to ... prevent the thing the second thread messes with from changing state. ...
    (comp.programming.threads)
  • Re: Interrupting threads...
    ... The solution highly depends of the whole environment you are working on ... why should the second thread fails to ... > Lets say i have 1 mutex, ... > if it's abandoned i'll get the lock in "thread2" anyways). ...
    (microsoft.public.win32.programmer.kernel)
  • Re: lock used in thread and by event
    ... event which calls first thread's eventhandler ... then the second thread will block. ... same basic behavior and semantics as the implicit monitor lock ... lock (foo) // No blocking here ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: monitor
    ... > This situation wont happen beacause the second thread already owns the ... The first thread have to wait until the second thread calls ... After the finally block the thread still owns the lock on *this*. ...
    (microsoft.public.dotnet.languages.csharp)