线程再次遇到thread_create语句会不会再次重启?

Will a thread be restarted again if it encounters the thread_create statement again?

我正在使用 pthreads,我怀疑如果线程遇到创建它的同一个 create 语句,它是否会再次重新启动?

Will a thread be restarted again if it encounters the thread_create statement again?

它会创建一个新线程,无论它是否被本身通过 pthread_create 创建的线程调用。

Lets say i have a thread t1. What happens if encounters the create statement, pthread_create(&t1,NULL,func,NULL). How can a new thread be created if i have a unique thread identifier , say the name t1?

在这种情况下,您仍在创建新线程,但只是 reusing/overwriting 先前的线程标识符 t1。这意味着您只能从线程函数中调用 pthread_join on the second you created but lose the ability to pthread_join, change attributes of the first thread, and so on on the first thread. Note that this is still valid. But if this is your use-case, you are probably better off creating detached threads (either by setting the attribute before creating the first thread or by calling pthread_detach)。分离的线程不能 加入 并且当线程退出时释放其资源(即,通过调用 pthread_exit 或从线程函数返回)。