CSE321 – Lecture 5 Solved

$ 24.99
Category:

Description

POSIX Thread:
In Linux platforms, the C language contains pthread standard API for all kinds of thread related functions. It is also known as a POSIX thread that allows users to create many threads for simultaneous processes to flow. It is best used in multi-core systems or processors to implement threads on the kernel to achieve the system.
Implementation:
(Library: #include <pthread.h>)
It is necessary to include this pthread.h header file in the script initially. This will help in using the functions of the pthread library. To compile and execute the c file consisting of pthread library following commands should be used. (Assume the name of the c file is th.c) gcc -o th th.c -lpthread
./th
Functions of pthread:
1. int pthread_create(pthread_t * thread_id, const pthread_attributes_t * attr, void *
(*thread_function), void *argument); Purpose: It is used to create a new thread. Parameters:
▪ thread_id: This acts as a pointer to an unsigned integer value. It returns the thread id of the thread that is formed.
▪ attributes: This parameter acts as a pointer to a structure. It is used to define attributes of a thread that can be the policy of scheduling, and stack address, etc.
▪ thread_function: This parameter is a pointer to the thread function of a thread.
▪ argument: This parameter is a pointer to void with different arguments to the function predefined at the start of the argument.
2. void pthread_exit(void *return_value); Purpose: It is used to terminate or end a thread. Parameters:
▪ return_value: It stores the status of the thread such that the thread terminates. It must be a
global variable. This will allow the next thread in line to join the thread if it is available.
3. int pthread_join(pthread_t thread_id, void *thread_return);
Purpose: This is a function used at the time of wait for the termination of the thread. Parameters:
▪ thread_id: It is the ID of the thread for which the thread in line waits.
▪ thread_return: It is the parameter that acts as a pointer to the particular location where we have defined the exit status.

Reviews

There are no reviews yet.

Be the first to review “CSE321 – Lecture 5 Solved”

Your email address will not be published. Required fields are marked *