Re: multi threading in C#



Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote:
By the way, as long as we're on the topic, there's been something I've
been curious about for awhile. I see in your example code, and I've seen
this elsewhere as well, the creation of a new, base object instance for
use as a locking object. I am curious what the point of that is, as
compared to simply acquiring a lock on the object you are trying to
synchronize access to.

For example, instead of using "listLock" for the lock() and Monitor
methods, why not just use the "queue" instance?

If you lock on a reference that only you have access to, that
guarantees that no-one else can screw things up by locking on it
themselves.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Is this easy locking of a Hashtables element too good to be true?
    ... When you are retrieving an ... synchronize access to that object, then you can lock on that. ... This creates a bottoleneck in my app. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with threads calling a function
    ... This is how the threads are calling the function: ... I believe the insertion is equivalent to a SendMessage() call. ... either of these needs a lock. ...
    (microsoft.public.vc.language)
  • Re: Damn you, FEDEX! or Nikon D40 lost in Springfield, MO blackhole.
    ... the 2 mp Mavica he had been using with a Nikon D40. ... After shopping around, he got me to order one for him. ... The shipper had it insured, but from what I have read it could take weeks to sort this crap out. ... You may get your insurance from FedEx and a couple weeks later they find it and deliver it. ...
    (alt.photography)
  • Re: Is this easy locking of a Hashtables element too good to be true?
    ... operations on a thread that deal with an element in the hash table. ... but it doesn't synchronize access to the hashtable ... I need to lock the "row" because the app is under heavy ... This creates a bottoleneck in my app. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: all threads : take a break!
    ... < I now want to do some major data update> ... create an object instance for use with the lock() statement ... Then you can use Monitor.TryEnterfrom the main update thread to try to acquire each of the working threads' locks; once it's finally gotten all of the locks, it can safely perform whatever update you need it to. ... As in the more basic solution, depending on how the threads depend on each other, you could either assign a specific locking object to each thread, or have the threads cooperate with each other as well as the main updating thread. ...
    (microsoft.public.dotnet.languages.csharp)