Programming on Multi-Core Processors Using Pthreads (POSIX Threads) |
Pthreads are defined as a set of C-language programming types and procedure calls,
implemented with a pthread.h header/include file and a thread library.
Solaris threads are easily
understood by someone familiar with POSIX threads, and while Java threads and the
multi-threading in the Win32 and OS/2 APIs are a little different . The subroutines,
which comprise the Pthreads APIs, can be formally grouped into three classes such as
Thread Management, Mutex Variables and Condition Variables. Threaded applications offer
potential performance gains and practical advantages over non-threaded applications
in several other ways as we can observe from the different programs.
Example programs using different APIs. Compilation and execution
of Pthread programs, programs numerical and non-numerical computations
are discussed using
different thread APIs to understand Performance issues on mutli-core processors.
The following Pthread programs is aimed to understand performance and scalability of large
number of insertions and deletions using various Pthread APIs and it can be applied to
producer - Consumer type of applications. Also, the tuning and performance with respect
to thread-affinity is included in-order to understand performance of this codes on
multiple sockets multi-core (many core) computing platforms.
|
Example 1.1
|
Write a Pthread program of producer/consumer using Mutex objects and Indexed-access of resource vector.
Producer-Consumer-Mutex-Array .
|
Example 1.2
|
Write a Pthread program of producer/consumer using Condition-variable and Indexed-access of resource vector.
Producer-Consumer-CondVariable-Array .
|
Example 1.3
|
Write a Pthread program of producer/consumer using Mutex objects and Sequential-access of resource vector.
Producer-Consumer-Mutex-LinkedList .
|
Example 1.4
|
Write a Pthread program of producer/consumer using Condition-variable and Sequential-access of resource vector.
Producer-Consumer-CondVariable-LinkedList .
|
Example 1.5
|
Analyze the performance for Pthread program of producer/consumer using different methods i.e. (1) Sequential-access of resource vector (Example 1.3), and (2) Indexed-access of resource vector (Example 1.1).
|
(Source - References :
Books
Multi-threading
-[MCMTh-01], [MCMTh-02], [MCMTh-I03], [MCMTh-05], [MCMth-09], [MCMth-11],
[MCMTh-15], [MCMTh-21], [MCBW-44] )
|
Description of Pthread Programs |
Example 1.1 :
Write a Pthread program of producer/consumer using Mutex objects and Indexed-access of resource vector.
( Download source code :
pthread_prod_cons_large.cpp
Makefile
README
)
|
- Objective
Write a Pthread program of producer/consumer using Mutex objects and Indexed-access of resource vector.
- Description
Write a Pthread program to produce and consume resources by 64 or more producer and consumer threads
respectively. This program makes use of Mutex objects provided by Pthread library to obtain mutually
exclusive access to the 'Resource Vector'. Resource Vector implemented using array.
- Input
Number of threads, Number of resources and Thread affinity mask (for default: no input)
- Output
Thread-affinity value (if set) , time taken to execute in seconds and micro-seconds
|
Example 1.2 :
Write a Pthread program of producer/consumer using Condition-variable and Indexed-access of resource vector.
( Download source code :
pthread_prod_cons_conditionVariable.cpp
Makefile
README
)
|
- Objective
Write a Pthread program of producer/consumer using Condition-variable and Indexed-access of resource vector.
- Description
Write a Pthread program to produce and consume resources by 64 or more producer and consumer threads
respectively. This program makes use of Condition-variable objects provided by Pthread library to obtain mutually
exclusive access to the 'Resource Vector'. Resource Vector implemented using array.
- Input
Number of threads, Number of resources and Thread affinity mask (for default: no input)
- Output
Thread-affinity value (if set) , time taken to execute in seconds and micro-seconds
|
Example 1.3 :
Write a Pthread program of producer/consumer using Mutex objects and Sequential-access of resource vector.
( Download source code :
prod_consumer_mutex_multi_access.c
)
|
- Objective
Write a Pthread program of producer/consumer using Mutex objects and Sequential-access of resource vector.
- Description
Write a Pthread program to produce and consume resources by 64 or more producer and consumer threads
respectively. This program makes use of Mutex objects provided by Pthread library to obtain mutually
exclusive access to the 'Resource Vector'. Resource Vector implemented using linked-list.
- Input
Number of threads, Number of resources and Thread affinity mask (for default: no input)
- Output
Thread-affinity value (if set) , time taken to execute in seconds and micro-seconds
|
Example 1.4 :
Write a Pthread program of producer/consumer using Condition-variable and Sequential-access of resource vector.
( Download source code :
prod_consumer_cond_multi_access.c
)
|
- Objective
Write a Pthread program of producer/consumer using Condition-variable and Sequential-access of resource vector.
- Description
Write a Pthread program to produce and consume resources by 64 or more producer and consumer threads
respectively. This program makes use of Condition Variable objects provided by Pthread library to obtain mutually
exclusive access to the 'Resource Vector'. Resource Vector implemented using linked-list.
- Input
Number of threads, Number of resources and Thread affinity mask (for default: no input)
- Output
Thread-affinity value (if set) , time taken to execute in seconds and micro-seconds
|
Example 1.5 :
Analyze the performance for Pthread program of producer/consumer using different methods i.e. (1) Sequential-access of resource vector (Example 1.3), and (2) Indexed-access of
resource vector (Example 1.1).
( Download WinRAR ZIP archive:
In-House-Producer-Consumer-Pthreads-codes (WinRAR ZIP archive)
|
- Objective
Write a Pthread program of producer/consumer using Sequential-access of resource vector and Indexed-access of resource vector
- Description
Write a Pthread program to produce and consume resources by 64 or more producer and consumer threads
using Sequential-access of resource vector and Indexed-access of resource vector.
- Input
Number of threads, Number of resources and Thread affinity mask (for default: no input)
- Output
Thread-affinity value (if set) , time taken to execute in seconds and micro-seconds
|
|
|
| |
|