[M3devel] __thread?

Jay jay.krell at cornell.edu
Tue Apr 28 18:32:16 CEST 2009


Mika, please let me know what this does for you, on the old FreeBSD 4.x?

Probably it'll give some compiler errors, but if not, excellent.

Our usess of pthread_get/setspecific should use __thread where it is available.
Below is FreeBSD/i386 7.0. Nice and efficient (even better with -O2).

Actually, "everyone", I'm interested in this.
Probably we should do a little local autoconfery in the m3core m3makefile.
If the below program compiles/links, use __thread, else pthread_get/setspecific.
Another option is determine that it is widely supported and use #if
or find out if there are specific #ifs associated with it. I know Cygwin doesn't support it.
 
 
[jay at jkfbsd1 ~]$ cat 1.c
#include 

__thread int a,b,c,d;

int main()
{
printf("%p%p%p%p\n", &a,&b,&c,&d);
return 0;
}
 
[jay at jkfbsd1 ~]$ gcc -S 1.c
[jay at jkfbsd1 ~]$ cat 1.s
        .file   "1.c"
        .section        .rodata
.LC0:
        .string "%p%p%p%p\n"
        .text
        .p2align 4,,15
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $20, %esp
        movl    %gs:0, %eax
        leal    d at NTPOFF(%eax), %eax
        movl    %eax, 16(%esp)
        movl    %gs:0, %eax
        leal    c at NTPOFF(%eax), %eax
        movl    %eax, 12(%esp)
        movl    %gs:0, %eax
        leal    b at NTPOFF(%eax), %eax
        movl    %eax, 8(%esp)
        movl    %gs:0, %eax
        leal    a at NTPOFF(%eax), %eax
        movl    %eax, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf
        movl    $0, %eax
        addl    $20, %esp
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
.globl a
        .section        .tbss,"awT", at nobits


...
 
 
 - Jay


More information about the M3devel mailing list