This fixes bug #667329.
The problem was that ManagedThreadId was created from a per-appdomain
counter, but stored in a per-thread storage, so if two threads could
end up with the same ManagedThreadId if a second appdomain executed
on the second thread first.
* mono-threads.c: An implementation of low level thread management that
fits what sgen needs. It uses hazard pointers to manage the thread list
since we can't protect it with the GC lock as this would cause boehm to
deadlock. This requires us to move small_id one layer down.
* Thread.cs:
* object-internals.h:
* threads.c: Small id is now stored on MonoThreadInfo so it can be
used by lower layers of the runtime such as sgen.
* sgen-major-copying.c:
* sgen-os-mach.c:
* sgen-os-posix.c:
* sgen-gc.h:
* sgen-gc.c: Replace sgen's thread management code with
the new one.
* boehm-gc.c: Hookup the new thread management code. Boehm's
own management code is not been replaced as I'm too much of
a coward to mess with it.
* hazard-pointer.c: Adjust to the new location of small_id.
This patchset implements a fast version of ThreadLocal<T> by reusing the code from
the implementation of the ThreadStatic attribute. The tls slots are cleaned up
on Dispose (or Finalize) instead of during appdomain shutdown.
Since C# doesn't allow us to define an icall that returns a T& or a T* type, a JIT
hack is used: every load field address instruction for the tlsdata field in
ThreadLocal<T> is intercepted and trasformed into a tls access by using the tls_offset
field from the same ThreadLocal<T> instance. So, while the C# code looks like
it accesses and changes an instance field, under the hood it will access the tls
storage.
The end result is that this is 5-6 times faster than the previous code, 10-15%
faster than using Thread.GetData () (when used with references).
This implementation also fixes a number of issues with disposing and with
per-thread initializers throwing an exception.
* Thread.cs (.ctor): Check if maxStackSize is negative
and raise and AOORE. Silently use a saner minimum size
of 128k as mono can't really run with much less than that.
* Thread.cs: Move culture data from InternalThread to Thread
and thus completely avoid the whole caching and serialization
nightmare. Even thou this is a cleanup it should speed up
multi-appdomain setups.
* threads.c: Remove culture caching machinery.
* icall-def.h: Ditto.
Fixes#318750 as a byproduct.
* Jumbo patch to drop support for pre-NET_2_0 code:
Remove ONLY_1_1 code
Remove NET_1_0 only code
Remove NET_2_0 defines assuming the value is true.
svn path=/trunk/mcs/; revision=145230
* Thread.cs (set_CurrentUICulture): Delay setting in_currentculture
to true until after the null check and the return statement.
svn path=/trunk/mcs/; revision=145214
* Thread.cs: change type of the current_appcontext field to object
to avoid triggering static constructors unless explicitely required.
svn path=/trunk/mcs/; revision=144431
* Thread.cs: Remove serialized culture icall stuff from
InternalThread. Implement it by using the cross-domain byte array
transfer icalls.
* Environment.cs: Corlib version bump.
svn path=/trunk/mcs/; revision=143040
* Thread.cs: Serialize the principal so as not to make it cross
appdomains. Two new internal calls for copying byte arrays
between domains.
2009-09-26 Mark Probst <[email protected]>
* Environment.cs: Corlib version bump.
svn path=/trunk/mcs/; revision=142671
* Thread.cs: The Thread class is split up into Thread and
InternalThread now. We have exactly one InternalThread per
thread, and at most one Thread per appdomain per thread. Most
data is stored in InternalThread. All InternalThread objects live
in the root domain.
* Environment.cs: Corlib version bump.
svn path=/trunk/mcs/; revision=142661
* ExecutionContext.cs: Don't use SecurityContext and don't expose
AsyncFlowControl for NET_2_1
* ThreadAbortException.cs: Remove ExceptionState from NET_2_1
* Thread.cs: Don't expose ApartmentState and remove Suspend and
Resume methods for NET_2_1
* ThreadPool.cs: Remove GetAvailableThreads and Unsafe* methods
for NET_2_1
svn path=/trunk/mcs/; revision=142481
2009-09-21 Sebastien Pouliot <[email protected]>
* Thread.cs: Remove CurrentPrincipal property for NET_2_1
* ExecutionContext.cs: Remove Run method for NET_2_1
In System.Security:
2009-09-21 Sebastien Pouliot <[email protected]>
* SecurityContext.cs: Don't use WindowsIdentity under NET_2_1
In System:
2009-09-21 Sebastien Pouliot <[email protected]>
* AppDomain.cs: Remove use of IPrincipal, Evidence and
PermissionSet types for NET_2_1
In .:
2009-09-21 Sebastien Pouliot <[email protected]>
* net_2_1_bootstrap_corlib.dll.sources, net_2_1_raw_corlib.dll.sources:
Remove most of System.Security.Policy and System.Security.Principal
and more of System.Security.Permissions from NET_2_1 build
In System.Security.Policy:
2009-09-21 Sebastien Pouliot <[email protected]>
* PolicyLevel_2_1.cs: Remove use of PolicyStatement
svn path=/trunk/mcs/; revision=142324
* Thread.cs: Always call Thread_free_internal from the finalizer, since
it frees other things besides the handle. Fixes#527576.
svn path=/trunk/mcs/; revision=139281
* object-internals.h : Adding interrupt_on_stop field.
* threads.c (mono_thread_request_interruption) : On Windows exit the
thread if interrupt_on_stop is set.
* socket-io.c (ves_icall_System_Net_Sockets_Socket_Accept_internal) :
Removing old interrupt logic and setting the interrupt_on_stop for the
thread when calling accept.
* socket-io.c (ves_icall_System_Net_Sockets_Socket_Receive_internal) :
setting the interrupt_on_stop for the thread when calling accept.
* Thread.cs : Adding interrupt_on_stop field.
Contributed under MIT/X11 license.
svn path=/trunk/mcs/; revision=136628
* Thread.cs: Refactor calling Moonlight's OnUnhandledException to
make sur the delegate it not called from a [SecuritySafeCritical]
caller.
* ThreadPool.cs: Reuse the above code for QueueUserWorkItem.
Original patch from Alan McGovern
svn path=/trunk/mcs/; revision=135866
* Thread.cs: Don't set the execution context when creating a
thread because the _ec member is thread static and we set the
wrong one. It's now set by the runtime. We just provide the
correct one.
* Environment.cs: Bump corlib version.
svn path=/trunk/mcs/; revision=134773
* Thread.cs: Make the execution context field thread-static to
avoid it being shared between app domains.
2009-04-21 Mark Probst <[email protected]>
* Environment.cs: Bump corlib version.
svn path=/trunk/mcs/; revision=132308
* Thread.cs: For 2.1 ensure exceptions in threads are handled using the
UnhandledException event mechanism in System.Windows.Application instead
of crashing the application.
svn path=/trunk/mcs/; revision=132166
* NumberFormatter.cs: Keep the current thread's number formatter
as a ThreadStatic member.
2009-04-18 Mark Probst <[email protected]>
* Thread.cs: Don't keep the current number formatter here
because it's shared between app domains.
svn path=/trunk/mcs/; revision=132067
2009-04-18 Mark Probst <[email protected]>
* Thread.cs: Make the abort exception state a GC handle, to
properly separate AppDomains. Add internal method for getting the
state object.
* ThreadAbortException.cs: Get the abort exception state via the
method in Thread.
2009-04-18 Mark Probst <[email protected]>
* Environment.cs: Bump corlib version.
svn path=/trunk/mcs/; revision=132063