Re: Using String.Empty as a SyncLock object
Tech-Archive recommends: Speed Up your PC by fixing your registry
On Mar 7, 7:51 am, iliti...@xxxxxxxxx wrote:
Are there any reasons against writing code like this?
class Foo
{
static string _SyncLock = String.Empty;
public void ThreadSafeMethod()
{
lock (_SyncLock)
{
// Code goes here
}
}
}
My only concern would be that string.Empty may be a singleton, and if
other code decides to lock on it, you could head a deadlock
condition. Might be better just to lock on an object.
.
Relevant Pages
- Re: Using String.Empty as a SyncLock object
... static string _SyncLock = String.Empty; ... public void ThreadSafeMethod() ... lock ... (microsoft.public.dotnet.languages.csharp) - Re: simplest thread safe pattern
... The actual threads in my app are spawned in higher-layer code -- this higher-layer code knows nothing of how data-access is implemented. ... While a thread is executing code inside the specific locked method, all other threads will need to wait until the current thread exits. ... Other methods in the class (even those that are locked in identical fashion) are not affected the lock. ... public void Method1() ... (microsoft.public.dotnet.languages.csharp) - Re: thread-safety
... It supports immediate addition to the consumer's queue, and creation of a repeating timer that will periodicially add to the consumer's queue. ... private TimeSpan _tsExecute; ... // the JobConsumer class while holding it's own lock. ... public void Add ... (microsoft.public.dotnet.languages.csharp) - Re: simplest thread safe pattern
... I hate to be the bad guy, but since you asked for the best way to accomplish it... ... While a thread is executing code inside the specific locked method, all other threads will need to wait until the current thread exits. ... Other methods in the class (even those that are locked in identical fashion) are not affected the lock. ... public void Method1() ... (microsoft.public.dotnet.languages.csharp) - Re: thread-safety
... and I started to use dotnet's queue collection with lock protection. ... private enum WorkerThreadState; ... private object stateLocker = new object; ... public void Start ... (microsoft.public.dotnet.languages.csharp) |
|