[Mono-bugs] [Bug 65414][Nor] Changed - [PATCH] Thread Local Data Slots do not survive nested appdomain transitions
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 7 Sep 2004 15:00:04 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by bmaurer@users.sf.net.
http://bugzilla.ximian.com/show_bug.cgi?id=65414
--- shadow/65414 2004-09-07 14:19:18.000000000 -0400
+++ shadow/65414.tmp.4634 2004-09-07 15:00:04.000000000 -0400
@@ -129,6 +129,55 @@
Do you have an idea where the ThreadStatic values are stored?
Apparently not: they are stored in a field pointed to by the Thread
object. So it is no different having the hash as a direct field in
MonoThread or having it as a field of a field which is what using
ThreadStatic makes it become. If you see different behaviour there is
some other bug or you didn't test properly.
+
+------- Additional Comments From bmaurer@users.sf.net 2004-09-07 15:00 -------
+There is a huge difference.
+
+Fields are assigned a slot in
+
+MonoVTable *
+mono_class_vtable (MonoDomain *domain, MonoClass *class)
+
+In this method there is the following code:
+
+ gint32 special_static =
+field_is_special_static (class, field);
+ if (special_static != SPECIAL_STATIC_NONE) {
+ guint32 size, align, offset;
+ size = mono_type_size (field->type,
+&align);
+ offset =
+mono_alloc_special_static_data (special_static, size, align);
+ if (!domain->special_static_fields)
+ domain->special_static_fields
+= g_hash_table_new (NULL, NULL);
+ g_hash_table_insert (domain-
+>special_static_fields, field, GUINT_TO_POINTER (offset));
+ continue;
+ }
+
+So ThreadStatic fields are per-appdomain, per-thread. This is very
+different from fields in the Thread class which are only per-thread,
+they are shared across appdomains.
+
+A good blog on this is here:
+
+http://blogs.msdn.com/cbrumme/archive/2003/04/15/51317.aspx
+
+By default, static fields are scoped to AppDomains. In other words,
+each AppDomain gets its own copy of all the static fields for the
+types that are loaded into that AppDomain. This is independent of
+whether the code was loaded as domain-neutral or not. Loading code
+as domain neutral affects whether we can share the code and certain
+other runtime structures. It is not supposed to have any effect
+other than performance.
+
+....
+
+Static fields marked with System.ThreadStaticAttribute are scoped per-
+thread per-AppDomain. You get convenient declarative thread-local
+storage over and above the normal per-AppDomain cloning of static
+fields.