الوحدة 4 · CS351

🎯 أهداف التعلم

Pseudocode
while (true) {
    entry section
        critical section
    exit section
        remainder section
}
Process Pi العملية Pi Start / بداية while (true) حلقة لا نهائية Entry Section قسم الدخول Critical Section القسم الحرج Exit Section قسم الخروج Remainder Section القسم المتبقي Enter / دخول Granted Release Continue / متابعة Next Iteration / التكرار التالي
Pseudocode
while (true) {
    flag[i] = true;
    turn = j;
    while (flag[j] && turn == j)
        ;
    /* critical section */
    flag[i] = false;
    /* remainder section */
}
Pseudocode
boolean test_and_set (boolean *target) {
    boolean rv = *target;
    *target = true;
    return rv;
}

// Solution using test_and_set
do {
    while (test_and_set(&lock))
        ; /* do nothing */
    /* critical section */
    lock = false;
    /* remainder section */
} while (true);
Pseudocode
while (true) {
    acquire lock
        critical section
    release lock
        remainder section
}
Pseudocode
wait(S) {
    while (S <= 0)
        ; // busy wait
    S--;
}

signal(S) {
    S++;
}
Semaphore Implementation (No Busy Wait) Semaphore Struct هيكل السيمافور value (integer) القيمة (عدد صحيح) queue (pointer) الطابور (مؤشر) Process P1 العملية P1 wait(S) انتظار value-- if (value < 0) block() Process P2 العملية P2 signal(S) إشارة value++ if (value <= 0) wakeup() points to head / يشير للرأس block() حظر Waiting Queue (Blocked) طابور الانتظار (محظور) P3 P4 ... Ready Queue طابور الجاهزية P5 P6 ... triggers / يُشغّل wakeup() إيقاظ
Busy Waiting (Spinlock) Blocking (Queue/Sleep)
🎓

حديث البروفيسور

❓ اسأل البروفيسور

البطاقات التعليمية

اختبر نفسك

1 / 10 🎯 نتيجتك: 0

🔐 خزنة الامتحان

🔑 مفهوم أساسي | Key Concept
⚠️ فخ | Trap
💡 سر | Secret
⚠️ فخ | Trap