What are Race Conditions?

What are Race Conditions?

CodeVault

3 года назад

89,296 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

NaN
NaN - 05.11.2023 18:06

Thread-safe-ness is a really important topic :) amazing explanation - enjoyed it, even though i already knew about it. never seen it in assembly though. loved that part, helps understanding the whole picture if you're not into it.

Ответить
React Code
React Code - 09.10.2023 18:16

sir one video create on setup phtread in vs code

Ответить
Yash Agrawal
Yash Agrawal - 01.10.2023 11:36

@codeVault Hello sir could you justify this statement. If threads run parallely then for the mail variable gets incremented by the two threads at the same time.
So the net increase in the count should be 1. As both the threads increment the mails variable at same time.

Ответить
malplena
malplena - 06.06.2023 15:40

Thank you so much!

Ответить
Makyxyz
Makyxyz - 01.06.2023 19:56

Wow, impressive clear and really fast to understand the concept. Thank you!

Ответить
Scott Gray
Scott Gray - 31.05.2023 09:45

It's also important to note the case when each thread reads the same value from memory, increments it and writes it back to memory, effectively "removing" one of the thread operations. I think this is more likely to happen than one thread being allowed to run multiple times before allowing the next to run and undo the work of the first thread

Ответить
Ahmet Karakartal
Ahmet Karakartal - 21.05.2023 20:10

wow, what a lesson, thank you so much

Ответить
Tomatte
Tomatte - 04.05.2023 18:13

thank you very much, it was amazing to see how the assembly do things

Ответить
Loner in the corner
Loner in the corner - 17.03.2023 16:31

2 words. Thank you.

Ответить
undeadpresident
undeadpresident - 05.03.2023 11:26

something to do with "white privilege" and colonialism?

Ответить
Tehuan Melo
Tehuan Melo - 26.01.2023 17:31

First time getting in contact with threads, you make the concept so easy to understand. Thanks a lot for the content!

Ответить
Mohamed Ali Chabani
Mohamed Ali Chabani - 19.01.2023 19:55

What if I'm working with threads and I get an unexpected value just like in the mailbox example. How can I tell if the result is due to a race condition or to an overflow ?

Ответить
Michael Lenczewski
Michael Lenczewski - 27.12.2022 23:16

You need to make that global variable volatile and make sure your compiler doesn't optimize your loop.

Ответить
Patrik Hyll
Patrik Hyll - 25.11.2022 21:53

Dude, this is great stuff! Excellent explanation skills

Ответить
Snowball Wang
Snowball Wang - 05.10.2022 17:34

Can I say race condition is more likely to occur when setting loop to 1 million because it takes longer time to finish the execution for each threads? In other words, thread p2 will be created after thread p1. But it is up to OS scheduler to decide which thread to run and how long it will run for one scheduling time slot. So if the execution time is very long and need more than just one scheduling slots, it is much easier to threads to interleave with each other. Is my understanding correct? Anyway, thanks for your great explanation in the video!

Ответить
Aymane Echafii
Aymane Echafii - 19.09.2022 08:42

Those from 42 Network, give it a like and good luck with the philosophers project! 🙏

Ответить
KosmonautOfficial
KosmonautOfficial - 31.08.2022 06:22

Great video! Thanks for the great explanation. I mainly use Python but this was very similar

Ответить
Sachin Kumar
Sachin Kumar - 29.08.2022 19:44

Why didn’t we created separate routine for both the threads and added a sleep in one thread to simulate one thread occupied while other is executing longer

Agree that race condition is not guaranteed but the probability will increase right?

Ответить
Ddddanny
Ddddanny - 24.07.2022 22:32

You should be extremely proud of yourself. You explained it beautifully.

Ответить
Wassim Bardusch
Wassim Bardusch - 16.07.2022 20:48

Hey,
First thing thank you very much for your Videos, could you name the IDE, which do you use ? and on which Operating system do you work ?

Ich hope of an answer :)

Ответить
Danilo Terzic
Danilo Terzic - 09.06.2022 19:13

Stunning explanation!

Ответить
peter emmanuel
peter emmanuel - 27.05.2022 19:58

Never seen race conditions broken down pragmatically like this in my life. I was awestruck when you took it to the assembly level. I couldn't believe my eyes. Thanks for this great video boss.

Ответить
Adham Adel
Adham Adel - 20.05.2022 20:29

You are Genius, i am cannot speak english very well but i want to say to you very very very thank you about this amazing explanation

Ответить
千禧 王
千禧 王 - 18.05.2022 07:18

Thank you! clearly explained

Ответить
Denny D
Denny D - 10.05.2022 19:23

it is a mass defect (nuclear mass) :)

Ответить
Muhamad Ridho Pratama
Muhamad Ridho Pratama - 06.04.2022 07:10

Thank you very much for all of your videos about processes and threads

Ответить
Tatiana K
Tatiana K - 29.03.2022 18:37

Thank you a lot for the video! Great as always :) Could you please explain why there is the same number (23) at "read mails" and "increment" steps? I assumed the incrementation step result is 24 as well as the "write" step

Ответить
Abhay Gaikwad
Abhay Gaikwad - 26.03.2022 10:36

understood

Ответить
Michael Tyutyunik
Michael Tyutyunik - 22.03.2022 00:59

I get so happy when I search up an OS topic and your video pops up because I know for a fact Ill understand it. Amazing work man!!

Ответить
Kavin Ashokan
Kavin Ashokan - 08.03.2022 12:28

according to your code there are 2 pthreads, with small numbers in mail variable increment both the thread excecuted sequentially (first thread 1 and after that thread 2). when you increased mail increment to 1000000 does thread one and thread 2 excecutes concurrently ? if they excecute concurrently, will this concurrent excecution will occur on single core cpu's ? or this concurrent excucution will happen only on cpu's with dual or more cores ? anyone please explain

Ответить
maybe
maybe - 06.03.2022 12:27

A 100 iterations didnt work because C compiler optimization turns loops where there is only one number incremented a couple times into "non loops", so a loop where x is inc. 10 times will be turned into x += 10 by the compiler. Thats why there were no race conditions with small numbers. Not because it takes too long or too short or smth ... .This optimisation stops at a certain number.

Ответить
TehObLiVioUs
TehObLiVioUs - 26.02.2022 06:00

Fantastic video totally understand now

Ответить
zxuiji
zxuiji - 24.02.2022 21:14

It occurs to me race conditions could be used to generate truly random numbers, something like:

void* rng_thread( void *ud )
{
while ( 1 )
{
rng_seed++;
pthread_yield();
}
}

The pthread_yield() is just there to give the system a chance to kill the app &/or thread

Ответить
zxuiji
zxuiji - 24.02.2022 21:01

Dude, you could give a simpler to understand explanation for noobs:

Think of each thread as a person, they each copy information from a document, they then modify that information and overwrite the old information, each person starts at different times but over time their timings align such that when one person copies information it is before the other person has updated the information with their own modified state meaning the information they modify is out of date and will cause the other person to get older information after they overwrite the documents information, the timing of the overwrites is the race condition

Ответить
Asheesh Mathur
Asheesh Mathur - 16.02.2022 04:18

Doing Wonderful Job ...that to for free. Service to humanity, sure you will be suitably rewarded.

Ответить
André Hernández
André Hernández - 10.02.2022 21:32

Ahahhaha he's so funny! It's charming to watch your videos. You have a very awesome vibe!

Ответить
attitude record
attitude record - 26.01.2022 16:14

You explain soooo well

Ответить
FrodosBeutel
FrodosBeutel - 26.11.2021 11:33

if professors could explain like you everyone would pass

Ответить
Enes B
Enes B - 16.11.2021 13:52

How did you open assembly page? I can't open it.

Ответить
dealvin pacman
dealvin pacman - 10.11.2021 00:34

but the pthread_exit() is important ? or not?

Ответить
Manuel Avendaño
Manuel Avendaño - 12.09.2021 22:57

Outstanding explanation mate

Ответить
ibrahim jabbar
ibrahim jabbar - 04.08.2021 20:34

as i heard from you that with threading that threads should go in parallel, as you show in a previous video example. Isnt race condition breaking the parallel thing here? very nice explanation

Ответить
Lavredis Goume
Lavredis Goume - 06.07.2021 12:53

Very clear explanation and a great course in total!

Ответить
Miki Cerise
Miki Cerise - 22.06.2021 21:38

Awesome stuff! One thing I don't get is how each thread's register would hold on to the value it originally read in a single CPU. If both threads are run on separate CPUs then it makes sense, but if they are both on the same CPU then surely the other thread will overwrite eax with its own value unless there are additional instructions to push the original value to another register or to memory to save it? Does the kernel do this automatically when it tells the thread to 'take a break'? :)

Ответить
Oliver YT
Oliver YT - 29.05.2021 03:21

As somebody who is just at the beginner level of C I can say, you produce the most "family friendly" (all the "horrors" of C compiled into nice, easy to follow explanations) videos on C. Well done!

Ответить
Praful Mohanan
Praful Mohanan - 07.05.2021 10:49

The OS subject should be taught like this, instead of whiteboarding.
This is to the point. Thanks!

Ответить