Although little weird, toilet is actually is a very good example for this! It's intuitive to understand that you "lock" it and that one person uses it at a time.
There can't be a better explanation than this. I luckily happened to watch this as my first video while studying the mutex vs semaphore concepts and I can say that it took me only the duration of this video to understand the very core principle associated with this topic. Thank you.
thank you for explaining this in terms of people using the toilet. its a great example. i finally get that a semaphore is basically just an atomic integer and a waiting-mechanism really. speaking of which i need to go park a turd now. thanks very much and wish me well for my crap
The only issue with your explanation is that when a mutex is locked, another thread trying to access the mutex doesn't get returned an error as you say. It just waits until the mutex is unlocked. I think you get it, just worded it improperly. Otherwise good video.
Thanks a billion times.....U have such an awseome talent of explaining the most difficult stuff in the easiest possible way..... Before watching ur videos ,I struggled with Computer science.... Ur channel & ur way of simple easy teaching increased my passion for Computer Science...I wish u all success & healthy happy life.. God bless u.. :-)
Every mutex is built on top of a semaphore with the addition of an atomic for the fast path. The fast path makes uncontended locking in userspace possible with a small number of instructions.
Welp, I found a way to ignore both of those, here's a snippet from what I'm currently constructing to give you an idea: ``` dint Send_AndWaitAll( THREAD *thread, OBJECT *object ) { BRANCH *branch = GrabThreadBranch( thread ); if ( !thread ) return 0; if ( thread != &main_thread ) { SIGNAL *signal = GrabThreadSignal(thread); OBJECT tmp = {0}; bool redo = false; object->que = time(NULL); signal->i = *object; while ( 1 ) { YieldOther(); /* Check if the thread sent us a signal */ if ( signal->o.que < object->que ) continue; /* Check if the signal was the one we were expecting */ if ( signal.o.sig != SIGNAL_CONT ) { tmp = signal->o; redo = true; continue; } break; } if ( redo ) { tmp.que = object->que; tmp.sig = SIGNAL_REDO; signal->i = tmp; } } Send_AndWaitAll( branch->Init, sig, object ); return Send_AndWaitAll( branch->Next, sig, object ); } ```
+echo Mutex allow only one process/thread to access shared data because of that it need to lock that object. Whereas semaphore multiple processes can be allowed and in order to notify them for availability of data signaling mechanism is used. Welcome to channel.
I didn't understand clearly. Is there a specific reason we used 4 toilets and 4 keys for Semaphore example ? If we want to understand the difference, we need to have same no. of toilets for both mutex and semaphore ? Also, if 4 toilets are there, and you take the key to use toilet, then also it looks like there is ownership. What is the advantage if we have same kind of key for all 4 bathrooms ? Isn't semaphore example same as having 4 mutexes for 4 toilets ? I can't imagine what is the advantage of having same key for all 4 toilets, Please help me understand.
Thanks for the video, but please buy a good microphone. If video quality is bad thats one thing but audio quality should always be good, otherwise people tune out quickly.
My textbook had so much abstraction and bullshit beating-around the bush with fornal words that I didn't understand anything. All I needed was the toilet example, with multiple keys.
Every theoric book says these things; I'd like to find a modern c++11/14 implementation. In real pratice we can't code description of the ideas but what we need are implementations
maybe the locks work in a way, that if somebody inserts the key into the lock from the inside it prevents turning the other key from unlocking the door
I think this difference is wrong, you have given example of counting semaphore , But we also have Binary Semaphore , Then what is difference bw binary semaphore and mutex.
Although little weird, toilet is actually is a very good example for this! It's intuitive to understand that you "lock" it and that one person uses it at a time.
I am on my way to a Computer Science degree. I have a very good professor but you explained it way better and made it easier.
There can't be a better explanation than this. I luckily happened to watch this as my first video while studying the mutex vs semaphore concepts and I can say that it took me only the duration of this video to understand the very core principle associated with this topic. Thank you.
You might have just saved my exams grade! I understood the explanation with the metaphore so much better and it sticks. Thank you!
don't think there's any saving if you call it a metaphore
@@omargamal2148 good one!
Of all possible examples in the world, you chose a toilet...
hahahaha!
Nishant Chauhan 😂
Lock(mutex)
"Do Work"
Unlock(mutex)
😂😂😂😂👏🏻👏🏻
Of all examples the toilet will probably be most memorable
Thank you so much! The toilet is such a good example for memorizing and understanding!
it actually really is.
believe or not your bathroom analogy helped me understood and finished my homework! Thank you so much.
Watch at 1.25x speed
me too :D
1.5x works fine for me
I watched this at 20x guys .. I think I win
I darieee you to watch it in 40x
1.25 almost english, at 2 becomes japanese
thank you for explaining this in terms of people using the toilet. its a great example. i finally get that a semaphore is basically just an atomic integer and a waiting-mechanism really. speaking of which i need to go park a turd now. thanks very much and wish me well for my crap
Beautiful explanation! I always had trouble understanding semaphores intuitively until you provided the brilliant bathroom key analogy!!
The only issue with your explanation is that when a mutex is locked, another thread trying to access the mutex doesn't get returned an error as you say. It just waits until the mutex is unlocked. I think you get it, just worded it improperly. Otherwise good video.
In implementation Mutex generates busy wait and starvation so I think he is right..!
to avoid this busy wait you need to do this... [s] is the flag/switch
mov ax, 0
xchg as, [s]
comp ax, 0
JNZ exit
sleep
exit
not necessarily...starvation doesn't happen often.
use mutex_try_lock() instead of mutex_lock()
thanks for the explanation i was confused
most clearly example to know mutex and semaphore.
Thanks
Great explanation. Made it all simple. For someone without a computer science degree, me.
very very tributary illustration. great video. the idea of mutex and semaphore really come to me translucid now
dude, you are a genius to use the toilet and key as the metaphor here.
honestly thankyou so much for this perfect example☺.... the concept got cleared
Very good explanation! Crisp and clean .
thanks
Thank you very much :) I also confused about the difference between mutexes and semaphores and you explained the difference very clearly.
thank you, your explanation is one of the best.
Very good explanation. Loved it.
All I could understand is "toilet."
A few times during this video I've been wondering if he did still use English
sent4dc 😂😂😂😂
Did u pass in the exam
Because you are full of s-hit.
Very clear and easy to follow explanation, thank you!
Great work! I now understand the difference the night before my exam. Many thanks Sir!
My frend its nice exemple it will stell in my memory for ever tanks
Thanks a billion times.....U have such an awseome talent of explaining the most difficult stuff in the easiest possible way.....
Before watching ur videos ,I struggled with Computer science.... Ur channel & ur way of simple easy teaching increased my passion for Computer Science...I wish u all success & healthy happy life.. God bless u.. :-)
Thanks for nice comment
It's really great.
Every mutex is built on top of a semaphore with the addition of an atomic for the fast path. The fast path makes uncontended locking in userspace possible with a small number of instructions.
best explanation i have ever seen
A clear and lucid explanation!
Very clear explanation. Thanks!
Best explanation ever
10/10, indian enough that it was a good tutorial!
Thanks for this video and it helps us to understand the main concepts in best way. and easy to remember the conepts.
Thanks
Welcome to the channel.
Welp, I found a way to ignore both of those, here's a snippet from what I'm currently constructing to give you an idea:
```
dint Send_AndWaitAll( THREAD *thread, OBJECT *object )
{
BRANCH *branch = GrabThreadBranch( thread );
if ( !thread )
return 0;
if ( thread != &main_thread )
{
SIGNAL *signal = GrabThreadSignal(thread);
OBJECT tmp = {0};
bool redo = false;
object->que = time(NULL);
signal->i = *object;
while ( 1 )
{
YieldOther();
/* Check if the thread sent us a signal */
if ( signal->o.que < object->que )
continue;
/* Check if the signal was the one we were expecting */
if ( signal.o.sig != SIGNAL_CONT )
{
tmp = signal->o;
redo = true;
continue;
}
break;
}
if ( redo )
{
tmp.que = object->que;
tmp.sig = SIGNAL_REDO;
signal->i = tmp;
}
}
Send_AndWaitAll( branch->Init, sig, object );
return Send_AndWaitAll( branch->Next, sig, object );
}
```
Now i clearly understand. Thank you sir
glad to know that :-)
I really like this toilet, sorry i mean tutorial
@@blazkowicz666 seriously? you are picking a fight over this comment? I have no idea why it's offending to you
@@zhengrui315 I thought that was something Racist implied before I watched the video. I have deleted the comment 🤝
🤣🤣🤣
Appreciate for your explanation!
He probably went to a dollar general where you have to get a key from the register for the bathroom.
Very good. But I think you need to explain why mutex use ownership while semaphore use signaling mechanism.
+echo Mutex allow only one process/thread to access shared data because of that it need to lock that object. Whereas semaphore multiple processes can be allowed and in order to notify them for availability of data signaling mechanism is used.
Welcome to channel.
Thanks for the awesome review!
welcome to the channel.
Seems a good explanation, but I struggled very hard to understand this english... Subtitles would be very nice (not automatic...)
is english your second language? maybe thats why it was hard.
yeah i couldn't understand it either. My professor used this video as required watching but im gonna search for something else I can understand.
Still very good explanation that made me understand, thank you
I still don't understand if the keys are identical, couldn't two threads access the same object and cause a race condition?
Very very nice explanation
Very Good.Keep it up :)
Welcome to channel.
HowTo सपना
Great video very clear
Wonderful explanation. Thank you! :)
How can someone dislike this video?
Yeah sure... cz there is a toilet in the video as an example.. duhhh
So basically, mutex is a way to assign keys to processes, and semaphore keeps track of how many keys are left?
thanks a lot for this explanation! you are awesome!
You are welcome.
Very good explanation.
very useful...Thanks
For the semaphore, if all the keys are identical what's to stop a person opening an occupied toilet door?
bhut umdaa
Thanks! Simple and straight to the point.
thanks
welcome to the channel.
What is the benefit of mutex over semaphore?
I didn't understand clearly. Is there a specific reason we used 4 toilets and 4 keys for Semaphore example ?
If we want to understand the difference, we need to have same no. of toilets for both mutex and semaphore ?
Also, if 4 toilets are there, and you take the key to use toilet, then also it looks like there is ownership.
What is the advantage if we have same kind of key for all 4 bathrooms ?
Isn't semaphore example same as having 4 mutexes for 4 toilets ?
I can't imagine what is the advantage of having same key for all 4 toilets,
Please help me understand.
thanks for the video, now I understand better
Welcome to the channel
Thanks for the video, but please buy a good microphone. If video quality is bad thats one thing but audio quality should always be good, otherwise people tune out quickly.
thanks for your concern.
I will improve audio definitely.
"Let's say this person wants to use toilet facilities" =)))))))))) Nice tutorial, thanks
Great explanation
This was a great explanation, thanks!
very nice expiation..Thank you..
Watching this for tomorrow interview
very well explained
awesome toilet example, i clearly understood
This video is half....people do have confusion between mutex and binary semaphore
Thank you Raja, I understand now.
Excellent presentation.
My textbook had so much abstraction and bullshit beating-around the bush with fornal words that I didn't understand anything. All I needed was the toilet example, with multiple keys.
what about P(mutex)V(mutex)? Does the semaphore now have ownership issues?
Thank you very clear was useful
thankyou sir for this video
Very very well method
I want difference between mutex and binary semaphore.
great Video!
What? Toilet example is funny one, Good explanation...
Every theoric book says these things; I'd like to find a modern c++11/14 implementation. In real pratice we can't code description of the ideas but what we need are implementations
So isn't mutex just a special case of a semaphore?
5:43 is it comparing if it is equal to zero not less than ..?
muchisimas gracias.. me quedo bien claro...gracias a ud
4 identical keys for the toilet!!! what if somebody already in toilet and another person come and open the toilet! LOL
maybe the locks work in a way, that if somebody inserts the key into the lock from the inside it prevents turning the other key from unlocking the door
This is the best question :)
Is binary semaphore and mutex same???
Thanks buddy for the informative video!
If two threads will try to access data with the help of semaphore at same time race condition can come. How can we avoid it
what software did you use to do the animation?
This is simple PowerPoint presentation
good explanation. Thanks..
good work in making the pictures
thanks
Welcome to the channel.
Mutex is just a simple lock?
Thank you for the video!
how can I close a mutex in a process? Tell me please how can I do it in a batch file or per cmd.exe.
Good example.
Good tutorial
I had to go to the toilet after watching this video..
these toilets must have gold basins,commodes,taps and stuff that is why they got keys
*Toilets must be a big problem elsewhere....*
good explanation
I think this difference is wrong, you have given example of counting semaphore , But we also have Binary Semaphore , Then what is difference bw binary semaphore and mutex.
thank you 😉😉😉😉😉
I hope none of these waiting people will throw timeout exception into his pants. Deferring the IO operation is dangerous thing.
Thank U