reversion_final_l1


"/home/yossef/notes/Su/os2/reversion_final.md"

path: Su/os2/reversion_final.md

- **fileName**: reversion_final
- **Created on**: 2026-01-01 20:08:15

lecture one

semaphore: make sure there is no two processes making release and require
executed at the same time

[EXAMPLE]
example about require and release for user:
if there is bathroom only 3 user on the bathroom:

with each semaphore there is waiting queue and there is operation with
this queue

deadlock: two or more processes waiting for event that can only casued
by only one of the waiting processes

starvation : a process will never remove from the semaphore queue which
is suspended (no resources for the process to execute)

classical problem of synchronization

LET'S CHAT ABOUT THIS

bounded buffer problem : so what is this is having another name is
the (producer consumer problem) so it's from the name is kind like produce
new resource and consume them and it's produce based on N (number of consumer)

Important

bounded buffer problem having a 3 value 0, 1, > [!NOTE]
0, this mean there is no resource no one gone get shit ;)) wait for produce
1, it's making sure that is only one person that gone enter semaphore(store)
N, it's kind a buffer for the places that can consume

[EXAMPLE]
now the best part is example if there is store for bread and there is people
that gone buy this bread so how this gone work!!

readers and writers problem : allow multiple user to read from store(disk)
and only one access at time when write to store(not allow to making more than
access to the disk to making write operation)

Dining philosophers problem : so this is nice one i gone say about the
example direct :

if there a group of four friends that is playing a game with controller
for example fifa 24 :)), but there is a problem there is only 2 controller

so it's kind like sharing what u have with you'r processes it's a nice
way

moniters : a high level mechanism that provide smart system to for process
synchroization making sure only one active process with same monitor each time

[EXAMPLE]
mointer is smart system just like a smart room when a user enter it's know
and activate and not allow any others users to enter untill the first user is
exit the room like electronic doors

condition variable : two operation conditions await and signal

x.await: call when making suspended for the process
x.signal: call when u resume the processes flow

Dining philosophers operation : takeFork, return Fork, eat
for example on the chop sticks example

if user want to get a chop: gone call take fork
and then eat using: eat
and then when finish call return fork: making a singals for others to
share between theme the chop sticks

Synchronization section

synchroization wait/notify :

class SharedBuffer {
    private int contents;
    private boolean available = false;

    // دالة المستهلك (للحصول على البيانات)
    public synchronized int get() {
        while (available == false) {
            try {
                // الخيط (Thread) ينتظر ويترك القفل لأن المخزن فارغ
                wait();
            } catch (InterruptedException e) {}
        }
        available = false;
        // تنبيه المنتج بأن المخزن أصبح فارغاً ويمكنه الإنتاج
        notify();
        return contents;
    }

    // دالة المنتج (لإضافة بيانات)
    public synchronized void put(int value) {
        while (available == true) {
            try {
                // الخيط (Thread) ينتظر لأن المخزن ممتلئ
                wait();
            } catch (InterruptedException e) {}
        }
        contents = value;
        available = true;
        // تنبيه المستهلك بأن هناك بيانات جديدة جاهزة
        notify();
    }
}

public class Main {
    public static void main(String[] args) {
        SharedBuffer buffer = new SharedBuffer();

        // خيط المنتج (Producer Thread)
        Thread producer = new Thread(() -> {
            for (int i = 1; i <= 5; i++) {
                buffer.put(i);
                System.out.println("المنتج وضع: " + i);
            }
        });

        // خيط المستهلك (Consumer Thread)
        Thread consumer = new Thread(() -> {
            for (int i = 1; i <= 5; i++) {
                int value = buffer.get();
                System.out.println("المستهلك أخذ: " + value);
            }
        });

        producer.start();
        consumer.start();
    }
}

notify : select specific theard from the wait set.
notifyAll : select all the notify on the wait set.

block synchronization : allowing specific block of code on the method
to sync.

Reentrant Locks : advanced controller on the sync function.

solaris synchronization : implementation for verity of locks to support
multitasking, multithreading, condition variables & readers-writers to make
sure many processes working in real time toghter.

adaptive mutexes : efficient when protect data from short code segment
short case.

condition variable & readers-writers : locks when longer section of code
need to access.

turnstiles : to order list of threads that is waiting to acquire
adaptive mutexes or condition variable & readers-writers.

transaction : collection of instruction or operation that performs signal
logic function

types of storage

voltile storage : information that is stored here not survive a crash system
like memory , ram, cache

nonvoltile storage : information usually survive a crash system
like disk, tap

stable storage : information never lost

logic recovery

log-based recovery : record all stable storage information about all
modification about all system

using undo and redo for moving on history modification

checkpoint : like making a point on system if u want to return back to it

Serializability

Serializability : it's like arange the order for execute process(like
reading and writing) on schedule

Operation in T0 Operation in T1 Conflict Status Description
Read(A) Read(A) No Conflict Both transactions are only viewing the data.
Read(A) Write(A) Conflict T1 is changing data that T0 is trying to read.
Write(A) Read(A) Conflict T0 is changing data that T1 is trying to read.
Write(A) Write(A) Conflict Both transactions are trying to update the same data.

continue:./l2.md
before:[[]]