1. Introduction

    System Information

  2. Inter-Process Communication
  3. Signals

    Programming in Various Environments

  4. Script Programming
    1. Script Variables
    2. Test Conditions
    3. Control and Iteration
    4. Commonly used Programs
    5. Shell Capabilities
    6. Example looping script
    7. Example using Variables
    8. Example working with files
    9. Example install script
  5. C and C++ Programming
    1. POSIX System Capabilities
    2. More POSIX
    3. Threads
    4. Mutexes
    5. An example viewmod program
    6. An example serial program
  6. X Programming
  7. Debugging
  8. Credits

Linux Threads

To invoke threads a data structure is utilized.

Thread Data Types

  • pthread_t
  • pthread_mutex_t - Mutex
  • pthread_cond_t - Condition variable
  • pthread_key_t - Access key for thread data.
  • pthread_attr_t - Thread attributes
  • pthread_mutexattr_t - Mutex attributes
  • pthread_condattr_t - Condition variable attributes
  • pthread_once_t - One time initialization

Thread Structure and Thread Functions

  1. pthread_t
  2. int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start)(void *), void *arg); - The thread identifier which is needed to do anything with the thread is the value returned in the first argument, *thread . The third argument is the address of the thread routine to run.
  3. pthread_t pthread_self (void);
  4. int pthread_detach (pthread_t thread); - Allows the system resources for the thread to be released when the thread exits.
  5. int pthread_join (pthread_t thread, void **value_ptr); - Blocks until the thread specified terminates. It will optionally store the return value of the terminated thread.
  6. int pthread_exit (void *value_ptr);
  7. int pthread_equal (pthread_t thr1, pthread_t thr2); - Returns 0 value if the threads are not equal and non-zero if they are the same thread.
  8. pthread_t pthread_self (void); - Allows a thread to get its own identifier.

Thread States

  1. ready - Ready to run in the system scheduler.
  2. blocked - Waiting for a mutex or resource.
  3. running - Running by the system scheduler
  4. terminated - The thread has normally exited or has called Pthread_exit to exit. Its resources have not been freed and will be freed if it is detached or joined.