Reputation: 38455
Well i writing in .net and i have a list to witch i will only add item never remove and its a linked list i can change that if its not the best pick but any way to the point would it be safe to not use any locking in this case when i know that this list will never be changed in any other manner but that its added to? (a lock will be used when trying to add to the list)?
Upvotes: 4
Views: 3603
Reputation: 1062540
No; to support many readers and one writer (comments to Jared's reply), you might want to look at ReaderWriterLockSlim
. The writer requires exclusive access; the readers can co-operate. This is what ReaderWriterLockSlim
does. There is also ReaderWriterLock
pre 3.5.
You will need to handle enter/exit etc manually - ideally via try/finally.
Upvotes: 6
Reputation: 754545
No it is not safe. LinkedList is not a thread safe class. The only supported multi-thread scenario for LinkedList is multiple readers
http://msdn.microsoft.com/en-us/library/he2s3bh7.aspx
Upvotes: 3