hw-join - if (rc) { printf("ERROR exit(-1) } }...

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 DocumentRight 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 DocumentRight 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(&quot;ERROR exit(-1) } } /* Free attribute and wait for the other threads */ pthread_attr_destroy(&amp;attr) for(t=0 { rc = pthread_join(thread[t], (void **)&amp;status) if (rc) { printf(&quot;ERROR return code from pthread_join() is %d\n&quot;, rc) exit(-1) } printf(&quot;Completed join with thread %d status= %d\n&quot;,t, status) } pthread_exit(NULL) Sheet1 Page 2 } Sheet1 Page 3 i&lt;1000000 i++) t&lt;NUM_THREADS t++) return code from pthread_create() is %d\n&quot;, rc) t&lt;NUM_THREADS t++) Sheet1 Page 4...
View Full Document

Page1 / 4

hw-join - if (rc) { printf(&amp;amp;quot;ERROR exit(-1) } }...

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