多くのシステムでは、スレッドのpthread_t
を一意の識別子として使用できます。これはpthread_self(3)
(POSIX)で取り出すことができます。 pthread_equal(3)
関数を使用して、2つの同値をテストすることができます。
pthread_t threadID = pthread_self();
if (pthread_equal(threadID, someOtherID) != 0)
/* Branch based on being the same thread */
else
/* Branch based on being different threads */
は、私の知る限り、pthread_getunique_np()
識別子としてpthread_t
を使用するよりも異なる固有の整数IDを返します。多くのシステムでは、pthread_self(3)
とf pthread_getunique_np()
の両方から返される値は同じです。実際には、pthread_t
ユニークな整数を取得する必要があります。
いずれにしても、呼び出されたスレッドのIDを返すためにpthread_self(3)
が必要です。この移植可能な関数を必要な方法で使用できるはずです。
(情報IBM約pthread_getunique_np()
)
は、異なる機能を使用して...?あなたのより広い目標を見て、別の解決策を見つけてください。 –