Threads and Thread Synchronization

Threads and Thread Synchronization - • The process table...

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

View Full Document Right Arrow Icon
Threads and Thread 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
Introduction to Threads A thread is a path execution By default, a C/C++ program has one thread called "main thread" that starts the main() function. main() --- --- printf( "hello\n" ); ---
Background image of page 2
Introduction to Threads You can create multiple paths of execution using: POSIX threads ( standard ) pthread_create( &thr_id, attr, func, arg ) Solaris threads thr_create( stack, stack_size, func, Windows CreateThread(attr, stack_size, func,
Background image of page 3

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

View Full DocumentRight Arrow Icon
Introduction to Threads Every thread will have its own Stack PC – Program counter Set of registers State Each thread will have its own function calls, and local variables.
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • The process table entry will have a stack, set of registers, and PC for every thread in the process. Multi-threaded Program Example #include <pthread.h> void prstr( char *s ){ while( 1 ){ printf( "%s",s); } } int main(){ // thread 2 pthread_create( NULL, NULL, prstr, "b\n" ); // thread 3 pthread_create(NULL, NULL, prstr, "c\n" ); // thread 1 prstr( "a\n" ); } Multi-threaded Program Example void prstr( char *s ){ while( 1 ){ printf( "%s",s); } } void prstr( char *s ){ while( 1 ){ printf( "%s",s); } } main(): void prstr( char *s ){ while( 1 ){ printf( "%s",s); } } T1 T2 T3 Output: Multi-threaded Program Example...
View Full Document

This note was uploaded on 01/30/2012 for the course CS 252 taught by Professor Gustavorodriguez during the Fall '11 term at Purdue.

Page1 / 7

Threads and Thread Synchronization - • The process table...

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

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