考慮下面的代碼例程何時傳遞給pthread_create開始?
#include <pthread.h>
void *pt_routine(void *arg)
{
pthread_t *tid;
tid = (pthread_t *) arg;
/* do something with tid , say printf?*/
/*
printf("The thread ID is %lu\n", *tid);
*/
return NULL;
}
int main(int argc, char **argv)
{
int rc;
pthread_t tid;
rc = pthread_create(&tid, NULL, pt_routine, &tid);
if (rc)
{
return 1;
}
printf("The new thread is %lu\n", tid);
pthread_join(tid, NULL);
return 0;
}
例行總能得到正確的tid
?
當然,我可以使用pthread來獲取自我ID,但我只是想知道例程運行的時間。
「在pthread_create()'的調用之後,」例程何時傳遞給pthread_create start?「?你的問題不清楚。 「例行公事能夠得到正確的結論嗎?」你什麼意思 ? – Stargateur
您將'&tid'作爲'pthread_create'(pthread_create'應該存儲新線程ID的地方)的第一個參數和'pthread_create'的第四個參數(要傳入'pt_routine'的參數) 。它*聽起來像是在詢問'pt_routine'是否可以運行並在'pthread_create'實際存儲線程的ID之前取消引用'arg'。那是對的嗎? – Wyzard