We have followed this convention in our code second

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ead has terminated, it terminates itself (and the entire process) by calling exit. code/threads/hello.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include "csapp.h" void *thread(void *vargp); int main() { pthread_t tid; Pthread_create(&tid, NULL, thread, NULL); Pthread_join(tid, NULL); exit(0); } /* thread routine */ void *thread(void *vargp) { printf("Hello, world!\n"); return NULL; } code/threads/hello.c Figure 11.5: hello.c: The Pthreads “hello, world” program. This is the first threaded program we have seen, so let’s dissect it carefully. Line 3 is the prototype for the thread routine thread. The Pthreads interface mandates that each thread routine has a single (void *) input argument and returns a single (void *) output value. If you want to pass multiple arguments to a thread routine, then you can put the arguments into a structure and pass a pointer to the structure. Similarly, if you want the thread routine to return multiple arguments, you can return a pointer to a structure. Line 5 marks the beginning of the main r...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online