Home > Documents > BASIC PRINCIPLES OF SYNCHRONISATION. MAIN CONCEPTS SYNCHRONISATION CRITICAL SECTION DEAD LOCK.

BASIC PRINCIPLES OF SYNCHRONISATION. MAIN CONCEPTS SYNCHRONISATION CRITICAL SECTION DEAD LOCK.

Date post: 19-Dec-2015
Category:
View: 229 times
Download: 7 times
Share this document with a friend
Embed Size (px)
Popular Tags:
of 26 /26
BASIC PRINCIPLES OF BASIC PRINCIPLES OF SYNCHRONISATION SYNCHRONISATION
Transcript
  • Slide 1
  • BASIC PRINCIPLES OF SYNCHRONISATION
  • Slide 2
  • MAIN CONCEPTS SYNCHRONISATION CRITICAL SECTION DEAD LOCK
  • Slide 3
  • Multiprogramming created an environment for concurrent classic processes.it also made available for a programmer to create a group of cooperating processes to work concurrently on a single problem. Multiprogramming created an environment for concurrent classic processes.it also made available for a programmer to create a group of cooperating processes to work concurrently on a single problem. how ever,multiple cooperating processes/threads introduce the potential for new synchronisation problems in software implementations such as: how ever,multiple cooperating processes/threads introduce the potential for new synchronisation problems in software implementations such as: dead lock dead lock critical section critical section non deteminacy non deteminacy
  • Slide 4
  • What is synchronisation Synchronisation Synchronisation it refers to the act of ensuring that independent processes/threads begins to execute a designated block of code at the same logical time it refers to the act of ensuring that independent processes/threads begins to execute a designated block of code at the same logical time Suppose a team has a plan for attacking a fort in which, each member of the team must be prepared to perform a specific task at exactly same time then 1.they must perform their actions at almost 1.they must perform their actions at almost exactly at the same time exactly at the same time 2.they must synchronize their watches by setting same time 2.they must synchronize their watches by setting same time
  • Slide 5
  • How syncronisation manifests itself in concurrent software Enter loop ANOTHER COMMAND ? ANOTHER COMMAND EXIT LOOP EXCUTE COMMAND WAIT FOR CHAILD TO TERMINATE YES NO FORK() CODECREATEPROCESS () CODE Unix shell Windows command launch
  • Slide 6
  • program UNIX While (TRUE){ //create a process to execute the command if((chPID =fork()) ==0) { if((chPID =fork()) ==0) { //this is the child Execv(command.name,command.argv); } //wait for the child to terminate thisChPID =wait(&stat); } Windows Windows While fgets(cmdline,MAX_LINE_LEN, FID)!NULL){ //b.create a new process to execute the command If(!create a new process to execute the command If (!createprocess(Null,cmdline,..) {/* error handling code*/} }
  • Slide 7
  • unix Parent program creates a child process to execute a command,then waits for the child to terminate before reading next command. Parent program creates a child process to execute a command,then waits for the child to terminate before reading next command. When this program processes 5 commands,then the processes that execute the commands will be created sequentially. When this program processes 5 commands,then the processes that execute the commands will be created sequentially. Concurrency between the parent and atmost one child at a time. Concurrency between the parent and atmost one child at a time.windows The parent process creates a process to execute a command,then immediately goes back to the top of the loop to create another process to execute another command The parent process creates a process to execute a command,then immediately goes back to the top of the loop to create another process to execute another command There is concurrency among the parent and all of the child processes There is concurrency among the parent and all of the child processes
  • Slide 8
  • Synchronizing multiple threads with shared variable initialize createThread() Wait runTime seconds ThreadWork exitterminate FALSE FALSEFALSE runFlag ? truetruetrue
  • Slide 9
  • Multiple threads Parent thread creates N child threads,each running as an iterative loop. Parent thread creates N child threads,each running as an iterative loop. At the end of the loop,each child checks to see if the RUN FLAG has been set FALSE, if not child iterates through the loop again. At the end of the loop,each child checks to see if the RUN FLAG has been set FALSE, if not child iterates through the loop again. If the RUN FLAG has been set FALSE,then the child terminates If the RUN FLAG has been set FALSE,then the child terminates
  • Slide 10
  • Program for multiple threads Static int runFlag =TRUE Void main({ //for 1 to n For (i=0;i

Recommended