Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Thread-Local Storage: gcc's __thread: (7 Items)
   
Thread-Local Storage: gcc's __thread  
Hello,
Is gcc's __thread keyword (http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-Local.html) supported in qnx neutrino? 
Code such as 
__thread int global=0;
compiles, but the assembler fails with errors such as "Error: junk `@NTPOFF' after expression".
Any help is greatly appreciated.
Sincerely, Thomas
Re: Thread-Local Storage: gcc's __thread  
> Hello,
> Is gcc's __thread keyword (http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-
> Local.html) supported in qnx neutrino? Code such as 
> __thread int global=0;
> compiles, but the assembler fails with errors such as "Error: junk `@NTPOFF' 
> after expression".

No, we don't have support for gcc's thread-local storage.

It shouldn't compile -- it should fail at the compiler stage not the assembler. Which compiler and target are you using?
 

qcc -V3.3.5,gcc_ntox86 tls.c
tls.c:1: error: thread-local storage not supported for this target

Regards,

Ryan Mansfield

Re: Thread-Local Storage: gcc's __thread  
Thank you for the quick reply. 
The following is a minimal example for triggering the error:

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
__thread int tls=0;

void* fnc(void *arg);

int main(int argc,char**argv)
{
   pthread_t thread1;
   pthread_create(&thread1,0,fnc,0);

   printf("main tls= %d\n",tls);
   return EXIT_SUCCESS;
}

void* fnc(void *arg)
{
   int i;
   for(i=0;i<100;i++)
     tls++;
   printf("thread %d, tls= %d\n",pthread_self(),tls);
}

Compiling with 
>> qcc -V3.3.5,gcc_ntox86  -S tls_minimal.c
on qnx 6.3.2 works.
However 
>> gcc tls_minmal.s 
>> qcc -V2.95.3,gcc_ntox86  -S tls_minimal.c
>> as  tls_minimal.s
all fail. 

Will "__thread" be supported in the upcoming release (6.4.0 with gcc
4.2)?

Sincerely,

Thomas Buschmann




On Tue, 2008-03-25 at 09:15 -0400, Ryan Mansfield wrote:
> > Hello,
> > Is gcc's __thread keyword (http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Thread-
> > Local.html) supported in qnx neutrino? Code such as 
> > __thread int global=0;
> > compiles, but the assembler fails with errors such as "Error: junk `@NTPOFF' 
> > after expression".
> 
> No, we don't have support for gcc's thread-local storage.
> 
> It shouldn't compile -- it should fail at the compiler stage not the assembler. Which compiler and target are you 
using? 
> 
> qcc -V3.3.5,gcc_ntox86 tls.c
> tls.c:1: error: thread-local storage not supported for this target
> 
> Regards,
> 
> Ryan Mansfield
> 
> 
> 
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post6091
> 
-- 
Dipl.-Ing. Thomas Buschmann

Technische Universitaet Muenchen
Lehrstuhl fuer Angewandte Mechanik
Boltzmannstrasse 15, D-85747 Garching

Phone: +49 89/289-15228
Fax  : +49 89/289-15213
eMail: buschmann@amm.mw.tum.de
WWW  : http://www.amm.mw.tum.de/People/buschmann.html


Re: Thread-Local Storage: gcc's __thread  
> Compiling with 
> >> qcc -V3.3.5,gcc_ntox86  -S tls_minimal.c
> on qnx 6.3.2 works.

Hmm, that's a bug. It should produced the not supported error message I pasted because we don't have the support for 
gcc's tls support.

> However 
> >> gcc tls_minmal.s 
> >> qcc -V2.95.3,gcc_ntox86  -S tls_minimal.c
> >> as  tls_minimal.s
> all fail. 

__thread wasn't introduced as a keyword until gcc 3 so this is expected.

> Will "__thread" be supported in the upcoming release (6.4.0 with gcc
> 4.2)?

I don't think the necessary OS support will make it in into 6.4 so unfortunately gcc 4.2 will have tls support disabled 
as well.

Regards,

Ryan Mansfield

Re: Thread-Local Storage: gcc's __thread  
Thanks a lot!
I'll just stick to POSIX functions then. 
Sincerely,

Thomas Buschmann

On Tue, 2008-03-25 at 11:30 -0400, Ryan Mansfield wrote:
> > Compiling with 
> > >> qcc -V3.3.5,gcc_ntox86  -S tls_minimal.c
> > on qnx 6.3.2 works.
> 
> Hmm, that's a bug. It should produced the not supported error message I pasted because we don't have the support for 
gcc's tls support.
> 
> > However 
> > >> gcc tls_minmal.s 
> > >> qcc -V2.95.3,gcc_ntox86  -S tls_minimal.c
> > >> as  tls_minimal.s
> > all fail. 
> 
> __thread wasn't introduced as a keyword until gcc 3 so this is expected.
> 
> > Will "__thread" be supported in the upcoming release (6.4.0 with gcc
> > 4.2)?
> 
> I don't think the necessary OS support will make it in into 6.4 so unfortunately gcc 4.2 will have tls support 
disabled as well.
> 
> Regards,
> 
> Ryan Mansfield
> 
> 
> 
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post6102
> 
-- 
Dipl.-Ing. Thomas Buschmann

Technische Universitaet Muenchen
Lehrstuhl fuer Angewandte Mechanik
Boltzmannstrasse 15, D-85747 Garching

Phone: +49 89/289-15228
Fax  : +49 89/289-15213
eMail: buschmann@amm.mw.tum.de
WWW  : http://www.amm.mw.tum.de/People/buschmann.html


Re: Thread-Local Storage: gcc's __thread  
To use thread local storage you can use posix functions: 
pthread_getspecific(), pthread_setspecific(), pthread_key_create(), and 
pthread_key_delete() .



Attachment: Text elaskavaia.vcf 94 bytes
Re: Thread-Local Storage: gcc's __thread  
Thanks, I will do that. 
I am interested in __thread, because it leads to better performance, at
least on linux.

On Tue, 2008-03-25 at 11:37 -0400, Elena Laskavaia wrote:
> To use thread local storage you can use posix functions: 
> pthread_getspecific(), pthread_setspecific(), pthread_key_create(), and 
> pthread_key_delete() .
> 
> 
> 
> 
> 
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post6104