3

変数を宣言しました:

static __thread int a;

次のエラーが表示されます。

致命的なエラー (dcc:1796): __thread は指定されたターゲット環境ではサポートされていません

どうすればこれを解決できますか? make ファイルでいくつかのフラグを有効にする必要がありますか?

私はwindriverコンパイラ(powerpc用にコンパイル)を使用しています。同様の質問を参照しましたが、理解できませんでした。

基本的に、再入可能な関数を作成しようとしています。どんな提案でも大いに役立ちます。

pthread.h を含めることでできることはありますか?

ありがとう。

4

2 に答える 2

3

__thread は gcc 拡張機能であり、すべてのプラットフォームで機能するわけではありません。上記のように、pthread_setspecific/pthread_getspecific を使用できます。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);
          }

しかし、再入可能な関数を作成しようとしているように、再入可能な関数は静的な非定数データを保持するべきではありません。

于 2011-05-18T12:52:39.150 に答える
2

__thread拡張機能です。同様のことを達成するための POSIX スレッド インターフェイスは pthread_getspecificpthread_setspecific

于 2011-05-18T11:35:21.223 に答える