1

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?

psubsee2003
  • 8,563
  • 8
  • 61
  • 79
SoftwareFactor
  • 8,430
  • 3
  • 30
  • 34
  • 1
    You 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 Answers1

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