- Introduction
System Information
- Inter-Process Communication
- Signals
Programming in Various Environments
- Script Programming
- Script Variables
- Test Conditions
- Control and Iteration
- Commonly used Programs
- Shell Capabilities
- Example looping script
- Example using Variables
- Example working with files
- Example install script
- C and C++ Programming
- POSIX System Capabilities
- More POSIX
- Threads
- Mutexes
- An example viewmod program
- An example serial program
- X Programming
- Debugging
- 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
- pthread_t
- 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.
- pthread_t pthread_self (void);
- int pthread_detach (pthread_t thread); - Allows the system resources for the thread to be released when the thread exits.
- 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.
- int pthread_exit (void *value_ptr);
- 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.
- pthread_t pthread_self (void); - Allows a thread to get its own identifier.
|
|
Thread States
- ready - Ready to run in the system scheduler.
- blocked - Waiting for a mutex or resource.
- running - Running by the system scheduler
- 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.
|
|