hw-join - if(rc printf"ERROR exit-1 Free attribute and...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_THREADS 3 void *BusyWork(void *null) { int i double result=0.0 for (i=0 { result = result + (double)random() } printf("Thread result = %e\n",result) pthread_exit((void *) 0) } int main(int argc, char *argv[]) { pthread_t thread[NUM_THREADS] pthread_attr_t attr int rc, t, status /* Initialize and set thread detached attribute */ for(t=0 { printf("Creating thread %d\n", t)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: if (rc) { printf("ERROR exit(-1) } } /* Free attribute and wait for the other threads */ pthread_attr_destroy(&attr) for(t=0 { rc = pthread_join(thread[t], (void **)&status) if (rc) { printf("ERROR return code from pthread_join() is %d\n", rc) exit(-1) } printf("Completed join with thread %d status= %d\n",t, status) } pthread_exit(NULL) Sheet1 Page 2 } Sheet1 Page 3 i<1000000 i++) t<NUM_THREADS t++) return code from pthread_create() is %d\n", rc) t<NUM_THREADS t++) Sheet1 Page 4...
View Full Document

{[ snackBarMessage ]}

Page1 / 4

hw-join - if(rc printf"ERROR exit-1 Free attribute and...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online