Hands-on; Shared Memory I; Threads

  1. Creation and Termination Threads, This example http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code41.c program creates 5 threads with the pthread_create() routine. Each thread prints a ``Hello World!'' message, and then terminates with a call to pthread_exit(). Compile as
    gcc -o code41 code41.c -lpthread
    
  2. Passing Arguments to Threads 1, This example http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code42.c program demonstrates how to pass a simple integer to each thread.
  3. Passing Arguments to Threads 2, This example http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code43.c program shows how to setup/pass multiple arguments via a structure. Each thread receives a unique instance of the structure.
  4. Passing Arguments to Threads 3 - Incorrectly, This example http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code44.c program performs argument passing incorrectly.

  5. Joining Threads, This example http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code45.c program demonstrates how to ``wait'' for thread completions by using the Pthread join routine. Since some implementations of Pthreads may not create threads in a joinable state, the threads in this example are explicitly created in a joinable state so that they can be joined later. Compile as
    gcc -o code45 code45.c -lpthread -lm
    
  6. Exercise: Complete this http://siber.cankaya.edu.tr/ozdogan/ParallelComputing/cfiles/code57_template.c template; which is a thread program for finding the minimum of a list of integers;
Cem Ozdogan 2010-11-29