Thread.FreeNamedDataSlot Method (String)

 

Eliminates the association between a name and a slot, for all threads in the process. For better performance, use fields that are marked with the ThreadStaticAttribute attribute instead.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

[<HostProtectionAttribute(SecurityAction.LinkDemand, SharedState = true,
    ExternalThreading = true)>]
static member FreeNamedDataSlot : 
        name:string -> unit

Parameters

name
Type: System.String

The name of the data slot to be freed.

System_CAPS_importantImportant

The .NET Framework provides two mechanisms for using thread local storage (TLS): thread-relative static fields (that is, fields that are marked with the ThreadStaticAttribute attribute) and data slots. Thread-relative static fields provide much better performance than data slots, and enable compile-time type checking. For more information about using TLS, see Thread Local Storage: Thread-Relative Static Fields and Data Slots.

After any thread calls FreeNamedDataSlot, any other thread that calls GetNamedDataSlot with the same name will allocate a new slot associated with the name. Subsequent calls to GetNamedDataSlot by any thread will return the new slot. However, any thread that still has a System.LocalDataStoreSlot returned by an earlier call to GetNamedDataSlot can continue to use the old slot.

A slot that has been associated with a name is released only when every LocalDataStoreSlot that was obtained prior to the call to FreeNamedDataSlot has been released and garbage-collected.

Threads use a local store memory mechanism to store thread-specific data. The common language runtime allocates a multi-slot data store array to each process when it is created. The thread can allocate a data slot in the data store, store and retrieve a data value in the slot, and free the slot for reuse after the thread expires. Data slots are unique per thread. No other thread (not even a child thread) can get that data.

This section contains two code examples. The first example shows how to use a field that is marked with the ThreadStaticAttribute attribute to hold thread-specific information. The second example shows how to use a data slot to do the same thing.

First Example

The following example shows how to use a field that is marked with ThreadStaticAttribute to hold thread-specific information. This technique provides better performance than the technique that is shown in the second example.

No code example is currently available or this language may not be supported.

Second Example

The following example demonstrates how to use a named data slot to store thread-specific information.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: