procsyn - PThread Synchronization Thread Mechanisms Birrell...

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

View Full Document Right Arrow Icon
PThread Synchronization
Background image of page 1

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

View Full DocumentRight Arrow Icon
Thread Mechanisms Birrell identifies four mechanisms commonly used in threading systems Thread creation Mutual exclusion (mutex) Waiting for events - condition variables Interrupting a thread’s wait First three commonly used in thread systems Take home message: Threads programming is tricky stuff! Stick to established design patterns.
Background image of page 2
Thread Creation in PThreads Type: pthread_t tid; /* thread handle */ tid returns pointer to created thread thread_attr specifies attributes, e.g., stack size; use NULL for default attributes start is procedure called to start execution of thread arg is sole argument to proc pthread_create returns 0 if thread created successfully pthread_join (tid, &retval); Wait for thread tid to complete Retval is valued returned by thread pthread_exit(retval) Complete execution of thread, returning retval
Background image of page 3

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

View Full DocumentRight Arrow Icon
Example #include<pthread.h> #include <stdio.h> /* Example program creating thread to compute square of value */
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course CSSE 250 taught by Professor Dr.yingwuzhu during the Spring '11 term at UH Clear Lake.

Page1 / 10

procsyn - PThread Synchronization Thread Mechanisms Birrell...

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

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