prac 3 : deadlock simulation Flashcards
library required to create thread
<pthread.h>
</pthread.h>
function to create thread,
step 1 : crate variable with thread datatype
ex pthread_t a;
pthread_create( & a , null thread_function, NULL)
- &a : adddress of thread
- null: default attribute
- name of function which contains whatever the thread is supposed to do
- null : input to this function. null implies nothing is passed to function
what header file library provides access to system calls and low-level I/O operations
include<unistd.h></unistd.h>
no of parameters to create thread in function and meaning of each
- &a : adddress of thread
- null: thread is going to acquire default attribute given by system
- name of function which contains whatever the thread is supposed to do
- null : input to this function. null implies nothing is passed to function
how to initialize thread :
pthread_t thread_name;
What function is used to wait for thread to finish ?
pthread_t a;
pthread_join(a, NULL)
a : the thread for which you want to wait
Null : this parameter tells just in case you want thread to return something, here means we want it to return nothing
what to include while running thread program in terminal
gcc prog_name.c -lpthread
how do we prototype thread function
void * thread_function (void * arg)
How to declare variable that is used for locking or unlocking ?
pthread_mutex_t
how to initialise variable declared for locking
pthread_mutex_init()
when thread wants to enter critical section what will it acquire to variable
pthread_mutex_lock()
when thread wants to go out of critical section what will it acquire to variable
pthread_mutex_unlock()