Pthread examples

This commit is contained in:
Shahram Najm 2016-11-21 14:03:17 +00:00
parent bd289bc8fd
commit d36ea27f48
2 changed files with 12 additions and 9 deletions

View File

@ -45,7 +45,7 @@ static void* process_bufr(void* arg)
int main(int argc, char** argv)
{
pthread_t thread1, thread2;
int error = 0, err = 0;
int err = 0;
FILE* fin = 0;
codes_handle* h1 = 0;
codes_handle* h2 = 0;
@ -56,11 +56,11 @@ int main(int argc, char** argv)
h2 = codes_handle_new_from_file(NULL, fin, PRODUCT_BUFR, &err); assert(h2);
fclose(fin);
error = pthread_create(&thread1, NULL, process_bufr, (void *)h1);
assert(!error);
err = pthread_create(&thread1, NULL, process_bufr, (void *)h1);
assert(!err);
error = pthread_create(&thread2, NULL, process_bufr, (void *)h2);
assert(!error);
err = pthread_create(&thread2, NULL, process_bufr, (void *)h2);
assert(!err);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);

View File

@ -67,6 +67,9 @@ int main(int argc, char** argv)
return 1;
}
}
pthread_exit(NULL);
for (i=0; i<NUM_THREADS; ++i) {
pthread_join(threads[i], NULL);
}
return 0;
}