LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-28-2006, 11:48 AM   #1
chlimouj
LQ Newbie
 
Registered: Aug 2006
Posts: 3

Rep: Reputation: 0
multithreaded programming and TLS


I posted this message in the normal LinuxQuestions forums under software/Linux Kernel before I realize this forum existed....




I'm new to threaded programming on Linux, and I've been reading a lot about the advancements in pthreads in the past couple years, but one thing I've been wondering is what is the big deal about thread-local storage?

Yes, I understand it is important for threads to be able to have their own local variables untouchable by other threads, but why can't this be implemented with just a malloc/free or new/delete? In both cases, the call is guaranteed to reserve a new memory location. I've actually implemented this in a little server I'm writing, and I have yet to see any adverse side effects... I've hammered it with several simulaneous connections and observed as many as 15 threads running concurrently (on a dual cpu system), and I did not notice any concurrency issues or memory overlapping.

So... why the TLS? Why deal with creating keys and pthread_getspecific, etc? Am I wrong in my understanding of what TLS is supposed to do?

-JC
 
Old 08-28-2006, 01:34 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
In a single-threaded application, you can make a variable "static" to preserve its value between function calls.

Consider "TLS" the moral equivalent of "per-thread static variables".
 
Old 08-29-2006, 01:00 AM   #3
chlimouj
LQ Newbie
 
Registered: Aug 2006
Posts: 3

Original Poster
Rep: Reputation: 0
So... it is preserved for subsequent threads after the thread dies? I was under the impression that TLS provided an untamperable "playpen" for each thread to use for its own non-shared variables... if I am not wrong in this, how does that play into the "static" analogy?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
new to multithreaded programming... why is TLS needed? chlimouj Linux - Kernel 1 08-30-2006 06:56 AM
multithreaded perl question chr15t0 Programming 12 06-26-2006 03:41 AM
wget multithreaded AlexiaKeth Linux - Software 1 06-25-2006 04:03 PM
when to start multithreaded and/or 64 bit! kahn Programming 3 07-11-2005 09:58 AM
Creating a Multithreaded Application kamransoomro84 Programming 3 06-03-2004 08:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration