考虑下面的代码例程何时传递给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