Professional Documents
Culture Documents
Operating Systems
POSIX threads
int main(){
pthread_t thread1, thread2;
char *message1 = "Hello from Thread 1";
char *message2 = "Hello from Thread 2";
return 0;
}
Questions
●
Are these two threads, orphan threads ?
●
Do these two threads invoke a system call ?
pthread_join()
●
The main process waits for a thread to terminate
●
int pthread_join(pthread_t thread, void **retval);
●
Change the previous code to use pthread_join()
pthread_self()
●
Returns the thread id (this is not the PID!)
●
Change the previous code to print out the thread
ids
pthread_yield()
●
Gives up using CPU resources so other threads can
make use of the CPU
●
Implemented using sched_yield()
– Requires #include <sched.h>
To be continued...
Any questions?
What to read
●
Dino book: 4.4.1, 4.6.1-3, 4.7.2
●
Tanenbaum book: 2.2.2–2.2.6, 10.3-10.3.3
Next class:
●
Week 3: Threads
– Commands
– OpenMP
– Pthreads examples