I am developing a multithreaded application where multiple threads are manipulating collections of items (List type). The actions being performed include adding, removing items, looping through items and performing calculations. I am currently using locking for synchronization, but with multiple shared collections and threads it is getting a bit complex. What patterns would you suggest to effectively share data between the threads, avoid race conditions and make the code easier to maintain?
Asked
Active
Viewed 175 times
1
-
1You gotta read this! http://www.albahari.com/threading/ A great resource on threading – Yahya Mar 22 '13 at 12:11
-
Duplicate? http://stackoverflow.com/questions/2980283/thread-safe-collections-in-net – Vizu Mar 22 '13 at 12:11
1 Answers
0
Well, getting multithreaded code correct is tricky.
I would suggest looking at the Collections in System.Collections.Concurrent
, they can be used without locks as long as you don't perform operations that needs transaction like behavior with multiple collections.

Albin Sunnanbo
- 46,430
- 8
- 69
- 108