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)?
+3
A:
No it is not safe. LinkedList is not a thread safe class. The only supported multi-thread scenario for LinkedList is multiple readers
JaredPar
2009-03-15 21:51:06
well thats what im trying to say sorry if i did write it a bit miss leading, many readers and only one writer... would that be safe, or atleast only one writer at the time.
Petoj
2009-03-15 21:54:41
@Petoj - reading would not be safe concurrently with a writer - even if the write is limited to a single thread.
Michael Burr
2009-03-15 22:16:55
+4
A:
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.
Marc Gravell
2009-03-15 21:58:08