我是pthreads的新手,我正在努力理解它.我看到了一些如下例子.
我可以看到它main()被API阻止了pthread_exit(),我已经看到了主要功能被API阻止的示例pthread_join().我无法理解何时使用什么?
我指的是以下网站 - https://computing.llnl.gov/tutorials/pthreads/.我无法获得何时使用pthread_join()以及何时使用的概念pthread_exit().
有人可以解释一下吗?此外,pthreads的良好教程链接将不胜感激.
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", …Run Code Online (Sandbox Code Playgroud)