Вы находитесь на странице: 1из 5

Creating a thread: Int pthread create(pthread-t * thread,constant p thread-attar-t & attar, void *(*routine)(void *), arg +arg); EAGAIN

N no of threads EINVAL Argument Errors ENONEM Numbers Sufficient Memory Joining a thread: Int_pthread join (pthread-t a thread, void ** strtosp); Terminating a thread: Int pthread exit(void * value p );

Code: #include<studio.h> Void MyThread (void *arg) Int main() { Pthread-t athread; Pthread_create(& athread,Mythread,NULL); Pthread_join (athread,NULL) Printf (Main thread existing); Return 0; } Void *Mythread (void *arg) { Printf (hello world); }

Scheduling: (Diagram)

Program Life Cycle: (Diagram) Process execution consists of a cycle of CPU execution & I/O wait

Dispatcher: Dispatcher module gives control of the CPU to the process selected by the scheduler; Dispatch Latency: Shifting of process & delay is created OR time it takes for the dispatcher to stop one process and start another running. Modes of dispatching: Scheduling Pre emtive & Non Pre emtive: 1.) 2.) 3.) 4.) Running state to wait state (an i/o request is put) (non preemptive because wait is compulsory) Running state to ready state (an interrupt occurs) (preemptive) Wait state to ready state (an i/o is completed) (preemptive) Process terminates (non preemptive)

Scheduling criteria: CPU utilization keep the CPU as busy as possible (maximize) Throughput # of processes that complete their execution per time unit (maximize) Turnaround time amount of time to execute a particular process (minimize) Waiting time amount of time a process has been waiting in the ready queue (minimize) Response time amount of time from when a request was submitted until the first response is produced. (minimize)

Process synchronization: Critical section: A piece of code in a cooperative process in which process may update shared data( files, variables, databases) Critical section problem: Serialize execution of critical sections in co operating process (it occurs when we read/write simultaneously) Entry section: within a code of process that takes us to problem is called entry section. Remainder section: Vice versa Solution for critical section problem: 1.) Mutual exclusion: of one process is in entry section then donot give access to any other process in critical/entry section. 2.) Progress: multiple processes accessing critical section then they will decide to enter new process or not. 3.) Bounded waiting: if a processes requests for accessing critical region then we bound requests from processes. Diagram:

Semaphor (Hardware solution) Synchronization technique in which we create conditional loop to check processes and its value is infinite. Having two calls (Signal & wait) (Diagram)

Disadvantage is this, it is extra process which is continuously running. Definition: A semaphore s, is an integer variable that apart from its initialization is accessible through two standard atomic(unit) calls. Signal (x) or wait (P). Deadlock: (Diagram) If process is in wait state for resource then it is called deadlock.

Resource Allocation Graph: (Diagram) Process denoted by circle. Resource denoted by square. Resource instance denoted by dots in square. (Diagram)

If there is circle in graph then there is deadlock.

Scheduling Algorothms: First Come First Serve (FCFS): (example)

Shortest Job First(SJF): (example)

Shortest Remaining Time First (SRTF): (example)

Вам также может понравиться