开发者

Thread local storage (TLS) - Compiler error

I have declared a variable:

static __thread int a;

I am getting the following error:

fatal error (dcc:1796): __thre开发者_如何学Pythonad not supported in the specified target environment

How can I resolve this? Should I enable some flags in make file?

I am on windriver compiler(compiling for powerpc). I referred to similar questions but unable to figure out.

Basically I am trying to make re-entrant functions. Any suggestion would be of great help.

Is there anything I can by including pthread.h?

Thanks.


__thread is gcc extension which is not working on all platform. As mentioned above you could use pthread_setspecific/ pthread_getspecific, there is an example from man:

          /* Key for the thread-specific buffer */
          static pthread_key_t buffer_key;

          /* Once-only initialisation of the key */
          static pthread_once_t buffer_key_once = PTHREAD_ONCE_INIT;

          /* Allocate the thread-specific buffer */
          void buffer_alloc(void)
          {
            pthread_once(&buffer_key_once, buffer_key_alloc);
            pthread_setspecific(buffer_key, malloc(100));
          }

          /* Return the thread-specific buffer */
          char * get_buffer(void)
          {
            return (char *) pthread_getspecific(buffer_key);
          }

          /* Allocate the key */
          static void buffer_key_alloc()
          {
            pthread_key_create(&buffer_key, buffer_destroy);
          }

          /* Free the thread-specific buffer */
          static void buffer_destroy(void * buf)
          {
            free(buf);
          }

But as I see you are trying to make re-entrant functions, reentrant function should not hold static non-constant data.


__thread is an extension. The POSIX thread interfaces to accomplish similar things are pthread_getspecific and pthread_setspecific

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜