http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56220



             Bug #: 56220

           Summary: g++ failed to initialize a __thread local bool

                    variable.

    Classification: Unclassified

           Product: gcc

           Version: 4.6.3

            Status: UNCONFIRMED

          Severity: major

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: gcc...@xiahaiqu.com





c++ front end failed to initialize a "__thread" local "bool" variable with

value "true" in a multi-threaded environment. I also did more tests, it could

initialize the variable to "false" correctly. Also it could initialize an "int"

variable correctly.



The bug would also be reproduced with both driver "gcc" and "g++":



witch@desktop:/tmp$ g++ --version

g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Copyright (C) 2011 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



witch@desktop:/tmp$ cat t.cpp

#include <stdio.h>

#include <pthread.h>



void g(bool x) {

    printf("%d\n", x);

}



void* f(void* arg) {

    static __thread bool i = true;

    g(i);

    return NULL;

}



int main() {

    pthread_t a, b;

    pthread_create(&a, NULL, &f, NULL);

    pthread_create(&b, NULL, &f, NULL);

    pthread_join(a, NULL);

    pthread_join(b, NULL);

    return 0;

}

witch@desktop:/tmp$ g++ t.cpp -O2 -pthread

witch@desktop:/tmp$ ./a.out 

1

1

witch@desktop:/tmp$ g++ t.cpp -O0 -pthread

witch@desktop:/tmp$ ./a.out 

0

0

Reply via email to