new to multithreaded programming... why is TLS needed?
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
|