Michael Schnell wrote: > > >TLS "Thread Local Storage" is the ability to say > > > > int __thread i; > > > I see ! Does using TLS create fast code or will there be a library > call done for any access to "i" ?
On most architectures it uses a CPU register, so no library call. On some ARMs it uses a fast call to a very short function provided by the kernel. > When I was thinking about the multithreaded application I am planning, I > found that I need a thread to know some unique ID. (I'll have multiple > threads that use the same code, so sometime they need to know which one > they are.). > > I see that this can be done with TLS. > Do you suggest that TLS is not available in a uCLinux system ? It's available on some uClinux systems. You can add support to yours, be my guest :-) > Is there any other way to have a unique thread ID that the thread can > _easily_and_fast_ access ? If you have a small number of threads, pthread_self() with LinuxThreads is ok. It searches a linear array to find which stack contains the current stack pointer. If you need it to be really fast and you don't have an MMU, you have to dedicate a register to holding something unique about each thread - either an id, or a pointer to a structure. That's what TLS does on many architectures. You can do itself if you're willing to recompile _everything_ (including libc etc.) telling GCC about the extra register, but that's usually a bad idea. With an MMU it's possible to store different values at the same address in each thread. TLS on some architectures works like that. With LinuxThreads you can use the portable pthreads method: pthread_getspecific(). It's not as fast as TLS, but not slow either. -- Jamie _______________________________________________ uClinux-dev mailing list uClinux-dev@uclinux.org http://mailman.uclinux.org/mailman/listinfo/uclinux-dev This message was resent by uclinux-dev@uclinux.org To unsubscribe see: http://mailman.uclinux.org/mailman/options/uclinux-dev