This is a mirror of official site: http://jasper-net.blogspot.com/

Working With Thread Local Storage (TLS) in C#

| Sunday, April 1, 2012
Thread-local storage (TLS) is a computer programming method that uses static or global memory local to a thread.  All threads of a process share the virtual address space of the process. The local variables of a function are unique to each thread that runs the function. However, the static and global variables are shared by all threads in the process. With thread local storage (TLS), you can provide unique data for each thread that the process can access using a global index. One thread allocates the index, which can be used by the other threads to retrieve the unique data associated with the index.

In the .NET Framework version 4, you can use the System.Threading.ThreadLocal<T> class to create thread-local objects.

System.Threading.ThreadLocal<T>

where T Specifies the type of data stored per-thread. The ThreadLocal(Of T) type exposes the following members.

Constructors

ThreadLocal(T)- The constructer used to initialize the ThreadLocal(T) instance.
ThreadLocal(T)(Tfunc(T))- This constructer is used to initialize the ThreadLocal(Of T) instance with the specified valueFactory function.
Properties

Value- This property is used to get or set the value of this instance for the current thread.
IsValueCreated- This property is used to get whether a value is initialized on the current thread.
Methods

Dispose()- This method is used to release all resources used by the current instance of the ThreadLocal(Of T) class.
Equals(Object)- This method determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Finalize()- This method is used to release the resources used by this ThreadLocal(Of T) instance. (Overrides Object.Finalize.)
GetHashCode()- This method serves as a hash function for a particular type. (Inherited from Object.)
GetType()- This method gets the Type of the current instance. (Inherited from Object.)
MemberwiseClone()- This method is uesd to create a shallow copy of the current Object. (Inherited from Object.)
ToString()- This method is uesd to create and return a string representation of this instance for the current thread. (Overrides Object.ToString.)
 
The .NET Framework provides dynamic data slots that are unique to a combination of thread and application-domain. There are two types of data slots: named slots and unnamed slots. Both are implemented by using the LocalDataStoreSlot structure.

To create a named data slot, use the Thread.AllocateDataSlot or Thread.GetNamedDataSlot method. To get a reference to an existing named slot, pass its name to the GetNamedDataSlot method.
To create an unnamed data slot, use the Thread.AllocateDataSlot method.

Read more: C# Corner
QR: Inline image 1

Posted via email from Jasper-net

15 comments:

Anonymous said...

Hi, I do think this is an excellent web site.
I stumbledupon it ;) I am going to revisit once again since i have saved
as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.
my website: acorn romeo shoes

Anonymous said...

Τhаnk you for the аuspісious ωritеup.
It in fact was a amusеment acсount it.
Looκ аdvanced tο morе adԁed agreeаble
from yоu! Hοwеνer, how can we communicate?
Also see my web page > http://hotmailcorreo.Webs.com

Anonymous said...

It's remarkable to pay a quick visit this web site and reading the views of all friends concerning this article, while I am also keen of getting knowledge.
Also visit my web page ... adjust browser settings

Anonymous said...

Hi there! I just wanted to ask if you ever have any issues with hackers?
My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no backup.

Do you have any methods to prevent hackers?
My page ; acoustic guitar solo amazing

Anonymous said...

Awesome post.
Feel free to surf my web site ko.dbpedia.org

Anonymous said...

Thanks a lot for sharing this with all folks
you really know what you're talking about! Bookmarked. Kindly also visit my web site =). We could have a hyperlink change contract among us
Take a look at my blog post : nokia e5 specification

Anonymous said...

Touche. Solid arguments. Keep up the great effort.
My page - adoption agencies in georgia

Anonymous said...

Wow, fantastic weblog layout! How long have you ever been blogging for?
you made running a blog glance easy. The overall look of your site is
magnificent, let alone the content material!
My weblog - hotmail search

Anonymous said...

Hi there! This is my first comment here so I just wanted to give
a quick shout out and tell you I really enjoy reading your blog posts.
Can you recommend any other blogs/websites/forums that cover the same subjects?

Thanks!

My website ... hotmail com sign in email inbox
my page :: old hotmail login screen

Anonymous said...

wonderful points altogether, you just received a new reader.

What may you suggest about your publish that
you just made a few days ago? Any sure?

my web blog :: meratol

Anonymous said...

I have been surfing online more than three hours today,
yet I never found any interesting article like yours. It is pretty worth enough for me.

In my view, if all web owners and bloggers made good content as you did, the
net will be a lot more useful than ever before.


my blog post: landing page design

Anonymous said...

The most we achieved was five PIDs of 17 offered. A great scanner not only retrieves difficulty codes, but identifies pending types way too.


my page - obdii scan tool

Anonymous said...

Bеcаuse thе admin of this site is woгking, no
unсertаintу very soon it will be well-known,
due to its featurе contents.

Heгe is my ωеb blog facebook cuenta gratis

Anonymous said...

After Ι initially commenteԁ I seem to have clicked the -Notify me
when neω commеnts are аddеd- checκbox
and now wheneveг а comment іs added I get four emailѕ with the eхaсt same comment.
There has to be a means you arе able tо гemοve me from that service?
Thanks!

my homeρаge; facebook cuenta gratis

Anonymous said...

This piece of writing offers clear idea in support of the new viewers of blogging, that really how to do blogging and
site-building.

Feel free to visit my blog post; hotmail email