[Mono-devel-list] Patch for Thread.GetNamedDataSlot

Jonathan Pryor jonpryor at vt.edu
Thu Jul 15 07:08:27 EDT 2004


On Wed, 2004-07-14 at 21:14, Sébastien Robitaille wrote:
> The problem: Thread.GetNamedDataSlot is not thread-safe. There is an
> exception thrown if multiple threads are calling this method at
> the same time.

<snip/>

+                       lock(typeof(Thread))
+                       {
+                               if (datastorehash == null)

<snip/>

You shouldn't lock the Thread class.  It is error prone and can lead to
deadlock.  You should instead lock a private object:

	private static object _lock = new object ();

	// ...
		lock (_lock) {
			// ...
		}

See also:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp

 - Jon





More information about the Mono-devel-list mailing list