Department of Information Technology Assignment No. 2 TITLE: Implement Multithreading For Matrix Multiplication Using Pthreads. Objective
Department of Information Technology Assignment No. 2 TITLE: Implement Multithreading For Matrix Multiplication Using Pthreads. Objective
pthread_create
Arguments:
thread - returns the thread id. (unsigned long int defined in bits/pthreadtypes.h)
attr - Set to NULL if default thread attributes are used. void * (*start_routine) -
pointer to the function to be threaded. Function has a single argument: pointer to
void. *arg - pointer to argument of function. To pass multiple arguments, send a
pointer to a structure.
pthread_exit
Arguments:
Thread Synchronization:
Mutexes:
Mutexes are used to prevent data inconsistencies due to race conditions. A race
condition often occurs when two or more threads need to perform operations on
the same memory area, but the results of computations depends on the order in
which these operations are performed. Mutexes are used for serializing shared
resources. Anytime a global resource is accessed by more than one thread the
resource should have a Mutex associated with it. One can apply a mutex to
protect a segment of memory ("critical region") from other threads. Mutexes can
be applied only to threads in a single process and do not work between
processes as do semaphores.
Joins:
A join is performed when one wants to wait for a thread to finish. A thread
calling routine may launch multiple threads then wait for them to finish to get
the results. One wait for the completion of the threads with a join.
The pthread_join() function waits for the thread specified by thread to terminate.
If that thread has already terminated, then pthread_join() returns immediately.
The thread specified by thread must be joinable.
Mutex functions:
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING
TATHAWADE, PUNE-33
(An Autonomous Institute Affiliated to Savitribai Phule Pune University,Pune)
ALGORITHM:
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING
TATHAWADE, PUNE-33
(An Autonomous Institute Affiliated to Savitribai Phule Pune University,Pune)
ASSIGNMENTS:
REFERENCES:
3. http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html