Carnegie Mellon, 410 Operating Systems

Çözen : Şadi Evren ŞEKER

Çözümler için şifre : www.setegitim.com

Identify and explain one reason for constructing a program so that it uses multiple threads instead of just one thread. We are expecting two to four sentences of answer.

Tek lifli (threaded) programlama yerine neden çok lifli (threaded) programalam kullanıldığını açıklayınız.

Cevap :


Joshua, Caroline, and Matt go to a Chinese restaurant at a busy time of the day. The waiter apologetically explains that the restaurant can provide only two pairs of chopsticks (for a total of four chopsticks) to be shared among the three people. Joshua proposes that all four chopsticks be placed in an empty glass at the center of the table and that eating should obey the following protocol.

/* Run by each philosopher */
while (!time_to_grade_P2()) {
   discuss_grading_plan();
   acquire_one_chopstick(); /* may block */
   acquire_one_chopstick(); /* may block */
   eat();
   release_one_chopstick(); /* does not block */
   release_one_chopstick(); /* does not block */
}

Üç kişi bir çin restoranında yemeğe giderler. Garson sadece 4 yemek çubuğu getirebileceğini söyler (bir kişinin yemek yemesi için en az iki çubuk gerekmektedir). Bu kişilerden birisi bütün çubukları ortadaki bir bardağa koyarak yukarıdaki algoritmayı kullanmayı önerir.

Bu algoritmada bir kilitlenme (deadlock) olmayacağını gösteriniz:

Suppose now that instead of three diners there will be an arbitrary number, D. Furthermore, each diner may require a different number of chopsticks to eat. For example, it is possible that one of the diners is an octopus, who for some reason refuses to begin eating before acquiring eight chopsticks. The second parameter of this scenario is C, the number of chopsticks which would simultaneously satisfy the needs of all diners at the table. For example, Joshua, Caroline, Matt, and one octopus would result in C = 14. Each diner’s eating protocol will be as displayed below.

int s, nsticks = my_chopstick_requirement();
while (!time_to_grade_P2()) {
   discuss_grading_plan();
   for (s = 0; s < nsticks; ++s)
      acquire_one_chopstick(); /* may block */
   eat();
   for (s = 0; s < nsticks; ++s)
      release_one_chopstick(); /* does not block */
}

Bu sefer D sayısında kişinin yemek yemek istediğini ve kişilerin çubuk ihtiyacını C ile gösterelim. Örneğin 8 kollu bir ahtopot ve üç kişi yemek yerken toplam çubuk ihtiyacı 2 + 2 + 2 + 8= 14 olacaktır.

Yukarıdaki açıklama ve algoritmaya göre kilitlenme (deadlock) olmaması için C ve D’ye bağlı olarak en az kaç çubuk gerekir?

Cevap:

Bu yazıyı beğendiyseniz, başkalarının da ilgisini çekebilirsiniz:


79 views

Leave a Reply


5 + beş =

Benzer Yazılar:

Bilgisayar Kavramları üzerinde şu anda okumakta olduğunuz 'Carnegie Mellon, 410 Operating Systems' isimli yazı 08 Oct 2009 tarihinde, saat: 14:49 'de Şadi Evren ŞEKER tarafından gönderilmiş, toplam79 defa okunmuştur.

Benzer yazıları Sınavlar kategorilerinden okuyabilirsiniz. Yazar ile irtibat kurmak için email gönderebilirsiniz. Yazıya yorum yapabilir ya da yapılan yorumları RSS 2.0 ile takibe alabilirsiniz.


Category: Sınavlar