Académique Documents
Professionnel Documents
Culture Documents
Threads use and exist within these process resources, yet are
able to be scheduled by the operating system and run as
independent entities largely because they duplicate only the bare
essential resources that enable them to exist as executable code.
1- Many-to-One Model
The many-to-one model maps many user-level threads to one kernel
thread.
2- One-to-One Model
The one-to-one model maps each user thread to a kernel thread.
3- Many-to-Many Model
The many-to-many model multiplexes many user-level threads to a
smaller or equal number of kernel threads.
Why Use Threads?
pthread_create (thread,attr,start_routine,arg)
pthread_exit (status)
Creating Threads:
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
Compile it by typing:
$ gcc thread.c o thread -lpthread
And run it:
$ ./thread
Assignment:
Given two matrices A and B, where A is a matrix with M rows and K
columns and matrix B contains K rows and N columns, the matrix product
of A and B is matrix C, where C contains M rows and N columns.
do a matrix multiply using threads where each thread does a single
multiplication and then the main thread will add up all of the results and
place them in the appropriate spot in the final matrix (after the other threads
have exited).
By: Eng.Takwa