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)?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With