﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Adding to list from multiple threads?</title><description>No, it is never safe without proper locking in place.
  
On a single processor, you have simply not been able to reliably reproduce the issue, but it certainly exists.
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment10</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment10</guid><pubDate>Thu, 12 Jul 2007 22:23:38 GMT</pubDate></item><item><title>Simone Busoli commented on Adding to list from multiple threads?</title><description>Ayende, maybe I'm missing the point, so adding to a list is safe as long as you're on a single processor?
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment9</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment9</guid><pubDate>Thu, 12 Jul 2007 21:22:13 GMT</pubDate></item><item><title>Simone Busoli commented on Adding to list from multiple threads?</title><description>However it looks strange to me... I should be experimenting at least some issues since so many threads are trying to add items to the list concurrently, but instead I have no troubles doing it, as if the list was thread safe...
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment8</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment8</guid><pubDate>Wed, 11 Jul 2007 12:29:50 GMT</pubDate></item><item><title>Ayende Rahien commented on Adding to list from multiple threads?</title><description>Simone,
  
That can certainly be the reason
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment7</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment7</guid><pubDate>Tue, 10 Jul 2007 18:19:07 GMT</pubDate></item><item><title>SimoneB commented on Adding to list from multiple threads?</title><description>Ayende, I'm having no troubles running your code, it runs fine with no errors in the additions... Can it be because your machine is a dual core?
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment6</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment6</guid><pubDate>Tue, 10 Jul 2007 16:49:59 GMT</pubDate></item><item><title>James Kovacs commented on Adding to list from multiple threads?</title><description>Just throwing in my 2 cents supporting Oren's example above. I always wonder why developers insist on "clever" algorithms, especially involving multi-threading. They use gut-feel to tell them whether a lock is required or whether finer-grained locking is appropriate. If you think multi-threading is easy, you haven't written enough multi-threaded code. Implement the simplest locking scheme possible (with unit tests to prove it actually works). Then when you measure a perf bottleneck in the locking code, implement a more performant algorithm and ensure your tests still pass. Premature optimization is the root of all evil. Premature optimization of locking code is evil incarnate (and just plain stupid).
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment5</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment5</guid><pubDate>Fri, 06 Jul 2007 16:55:48 GMT</pubDate></item><item><title>roy osherove commented on Adding to list from multiple threads?</title><description>now, why didn't you use the threadtester I wrote? it's just for these types of cases..
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment4</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment4</guid><pubDate>Fri, 06 Jul 2007 16:06:43 GMT</pubDate></item><item><title>Ayende Rahien commented on Adding to list from multiple threads?</title><description>thanks, fixed.
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment3</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment3</guid><pubDate>Fri, 06 Jul 2007 08:46:00 GMT</pubDate></item><item><title>Damien Guard commented on Adding to list from multiple threads?</title><description>I think you mean "multiple threads" not "multiply".
  
  
One means many the other is a mathematical operation.
  
  
[)amien
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment2</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment2</guid><pubDate>Fri, 06 Jul 2007 06:39:10 GMT</pubDate></item><item><title>Jimmy Bogard commented on Adding to list from multiple threads?</title><description>MSDN documentation will tell you if a class is thread-safe or not:
  
  
http://msdn2.microsoft.com/en-us/library/6sh2ey19.aspx
  
  
Down at the bottom in the "Thread Safety" section, it says that List&lt;T&gt; is not thread-safe for instance methods.  I usually start at MSDN documentation to determine if I need to lock a resource or not.
</description><link>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment1</link><guid>http://ayende.com/2621/adding-to-list-from-multiple-threads#comment1</guid><pubDate>Thu, 05 Jul 2007 22:30:24 GMT</pubDate></item></channel></rss>