Re: Creating a Shared Lock
- From: "Bob Bins" <msgdev@xxxxxxxxxxx>
- Date: Fri, 17 Mar 2006 12:55:51 -0500
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.
|
|
.
- Follow-Ups:
- Re: Creating a Shared Lock
- From: William Stacey [MVP]
- Re: Creating a Shared Lock
- References:
- Creating a Shared Lock
- From: Bob Bins
- Re: Creating a Shared Lock
- From: William Stacey [MVP]
- Creating a Shared Lock
- Prev by Date: Updating database using DataView
- Next by Date: Trouble with TreeNode Remove()
- Previous by thread: Re: Creating a Shared Lock
- Next by thread: Re: Creating a Shared Lock
- Index(es):
Relevant Pages
|