1

私のアプリケーションは、pthread_create() で複数のスレッドを作成し、pthread_kill(threadId, 0) でそれらの存在を確認しようとします。たまに pthread_kill が「そのようなプロセスはありません」で失敗します...

pthread_create の後で pthread_killを呼び出すのが早すぎたのでしょうか? pthread_create() によって返される threadId はすぐに有効になると思いましたが、常にそうであるとは限りません...

pthread_create() 自体の戻り値を確認します-失敗していません...コードスニペットは次のとおりです。

    if (pthread_create(&title->thread, NULL,
        process_title, title)) {
        ERR("Could not spawn thread for `%s': %m",
            title->name);
        continue;
    }
    if (pthread_kill(title->thread, 0)) {
        ERR("Thread of %s could not be signaled.",
            title->name);
        continue;
    }

そして、時折、シグナルを送信できなかったスレッドに関するメッセージが表示されます...

4

1 に答える 1