انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

semaphore-part2

الكلية كلية العلوم للبنات     القسم قسم الحاسبات     المرحلة 4
أستاذ المادة سحر عادل كاظم عبود باوي       5/31/2011 6:42:04 AM

Critical Section: Attempted Solution

 

Shared Variable:

 

int v=0; /* v==0 => critical section OPEN; v==1 => critical section CLOSED */
    

 

Code: At p_i in {1,...,n}:

 

   while (1) {
    

 


    

 

     /* trying region */
    

 

     while (v == 1)  /* do nothing */ ;
    

 

     
    

 

     v = 1;
    

 

     /* critical section (region) */ 
    

 


    

 

     x = 0;
    

 

     x++;
    

 

     printf x;
    

 


    

 

     v = 0;
    

 

     /* remainder region */   
    

 

   }
    

 

  • what is wrong? what if critical section is: dial_phone("555-1212")?

     

  • how can it be fixed?

     

  • is this spinlock good or bad?

     



Critical Section: General Problem  

 

  • n processes each with segment of code called critical section

     

  • one process changes common (shared) variables, writes to a file.

     

  • no other process is allowed to execute in its critical section

     

  • execution of critical sections is mutually exclusive in time

     

  • one solution: semaphore

     

  • lets one process into the critical section

     

  • puts other processes in a semphore queue (no busy waiting)

     

  • process is finished: head of FIFO queue enters section

     




المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .