Quote:
Originally Posted by EpvpIsAJoke
Yeah, sure, you can use the concurrent collections that people from Microsoft with decades of experience in writing lock-free algorithms/data structures made for you, but that's not to say that your program doesn't use locks. Even some of the concurrent collections (ConcurrentBag and ConcurrentDictionary for example) use locking, which means you're still using locking even if you didn't explicitly write the lock statements in your code yourself.
|
Sure, and if you bother to read up on how specific classes work you can minimise lock statements if they are causing issues. Of course when your using Parallel in conjunction with Concurrent collections your likely not going to find a better combination in terms of performance unless you take it to the extremes and work at extremely low levels.
But like I said its all about your design, Concurrent collections are slower than their regular counterparts so its a trade off as with most design choices. Is it quicker to use the slower collection which scales better across multiple threads, or use the faster collection which isn't thread safe unless you put a bunch of wrapping around it and in turn trade more performance for safety.
Typically if your going to be using alot of multi-threading then Concurrent collections are the way to go, if you know the collection will only ever be accessed by one thread at a time then always pick the standard collection, that's as complicated as it needs to be.