Lecture 16: Critical Section Problem || Race condition in OS

preview_player
Показать описание
This video provides an engaging glimpse of Thread Scheduling Problem, we have also discussed Peterson's Solution and Mutex/Locks.

There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “

Slides:

Do provide you feedback in the comments, we are going to make it best collectively.

Connect with Lakshay:

Connect with Babbar here:

Telegram Group Link: Love Babbar CODE HELP

Timestamps

00:00 - Introduction
01:48 - Promotion
02:48 - Critical Section and Race condition
11:02 - Hands-on example of Race condition
13:26 - Solution to overcome Race condition
16:10 - Hands-on example to overcome Race condition using locks
18:00 - Conditions a Solution should have to solve Critical-section problem
21:20 - Can we use single flag to overcome Race condition
24:55 - Peterson's solution
29:30 - Locks and its disadvantages

Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.

#OSBusted #Lakshay
Рекомендации по теме
Комментарии
Автор

peterson's solution for critical section was not properly explained, there's still some confusion..

vinamrajha
Автор

thank you for giving this series of OS, commenting to let you know that someone still loves to complete your series slowly but efficiently.

leeavi
Автор

thank you for all your effort, it is highly appreciated. I had zero clue about using locks in my code and things like that ...this feels like some hidden knowledge that no one ever talks about

again, thanks a tonne for all your effort <3

Sunshine
Автор

27:02 pe critical section mai kaise jaa sakta hai dono case mai to loop mai jaayega na condition k hisaab se?? ya samjhane mai koi mistake hai sir ke

VishnuKumar-kjxh
Автор

23:45 pe agar turn = 0 hoga to?
T1 me jake while ( turn! = 0 ) ayega to condition false ho jaega
To bhaiya T1 me jaega kyu bol rahe he?

yashchampaneri
Автор

It's a request please add English subtitles . I can't keep up with the following videos and appreciate your work in OS videos.

NavelsUrith
Автор

very good technique ..hands on learning is better to understand and remember concepts

sarthakgokhale
Автор

The line while (turn != 0); is where it gets sneaky. That little " ; " at the end means the loop is just vibing (doing nothing) until turn == 0. Once it hits 0, you finally get into the Critical Section.
I tripped up here 22:05, or the 8th section of the video.

ELECTROMIST
Автор

I have a doubt. There should be no context switching between threads right because they are executing concurrently. But still context switching happens. I don't understand why? Can someone clear my doubt?

sachinsharma
Автор

One of the best explanations of CS Problem !

jatingarg
Автор

The subtitle is not available after the lecture number 15 as the subtitle is autogenerated i cannot properly understand things.

puppy
Автор

At 24:01 while loop condition is false . then how will control enter while loop ? bhaiyaa ye thoda confusing ho gyyyaa.

Heartless-hekm
Автор

@Lakshya Kumar what if in peterson's solution context switch is done at line no. 2 then the both the threads will go in waiting state

sangammishra
Автор

@CodeHelp Yeh Global Interpreter Lock [12:09] me kyu ni work kr rha hai?

kevinmartin
Автор

Subtitles would be useful for me, since i followed all the above videos which has subtitles. Kindly provide the needful

logeshwar
Автор

From this video, explaination is weak.

deepakabari
Автор

How can either of the the threads enter critical section initially?
Let's understand this STEP BY STEP Clearly.

The main point to be noted is that initially none of the threads are ready.
So flag[2]={false, false};

a)Assume T1 wants to enter first

i) Flag[0]=1; //t1 says "I'm ready"
ii) turn=1; //I am humble and I am allowing T2 to execute if it's ready.

while( turn==1 && flag[1]==True);
Let's understand this while condition by breaking both conditions individually :
// is it thread2's turn==>Yes, because thread1 is humble and it has allowed to do so on line (ii)
// MAIN QUESTION::is thread2 ready ??==> No because remember we initially said no one is ready.
//Hence, we'll not be stuck in this infinite loop and enter critical section with Thread1



b) Assume T2 want to enter first

Flag[1]=1; //t2 says "I'm ready"
turn=1; //I am humble and I am allowing T1 to execute if it's ready.

while( turn==0 && flag[0]==True);
Let's understand this while condition:
// is it thread1's turn==>Yes
// is it ready ??==> No because remember we initially said no one is ready.
//Hence, we'll not be stuck in this infinite loop and enter critical section with Thread2

jaiminjudal
Автор

void task(){
while(1)
if (flag==0){
flag = 1;
for(int i =0 ; i < ++I)
++count;
flag = 0;
break;
}
}

I guess this should work fine. I am not sure why was there different conditions for different thread in the turn flag example.

RohitSingh-ztlq
Автор

agar do threads parallel na chale jaise hum locks mai sequential hi chala rhe hai toh threads ka motive hi khatam hoo gya yaha toh ??

utpalraj
Автор

Hey, my Linux system has 4 cores and therefore, I took 6 threads (so that context switching occurs). Still, I'm getting the perfect answer without using Mutex (in my case 60 lacs). Can someone explain this?

aritramajumder