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.
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.
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
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 ); } ```
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.
its only theoretical concept dear. totally confusing video :(. You need to explain it's main purpose why we have to use mutex and why we have to use semaphore
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.
+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.
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.
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.
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.
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
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
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 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 🤝
🤣🤣🤣
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
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.
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.
thank you, your explanation is one of the best.
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
"Let's say this person wants to use toilet facilities" =)))))))))) Nice tutorial, thanks
Thank you so much! The toilet is such a good example for memorizing and understanding!
it actually really is.
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
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 );
}
```
Very Good.Keep it up :)
Welcome to channel.
HowTo सपना
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.
How can someone dislike this video?
Yeah sure... cz there is a toilet in the video as an example.. duhhh
most clearly example to know mutex and semaphore.
Thanks
He probably went to a dollar general where you have to get a key from the register for the bathroom.
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!
I want difference between mutex and binary semaphore.
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 :)
I still don't understand if the keys are identical, couldn't two threads access the same object and cause a race condition?
10/10, indian enough that it was a good tutorial!
*Toilets must be a big problem elsewhere....*
What is the benefit of mutex over semaphore?
Great explanation. Made it all simple. For someone without a computer science degree, me.
Instead of calling the class "Mutex", how about Microsoft should have called the class "Toilet" instead LOL.
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.
My frend its nice exemple it will stell in my memory for ever tanks
Mutex is just a simple lock?
Thanks for the awesome review!
welcome to the channel.
This video is half....people do have confusion between mutex and binary semaphore
its only theoretical concept dear. totally confusing video :(. You need to explain it's main purpose why we have to use mutex and why we have to use semaphore
I had to go to the toilet after watching this video..
honestly thankyou so much for this perfect example☺.... the concept got cleared
Thank you very much :) I also confused about the difference between mutexes and semaphores and you explained the difference very clearly.
I hope none of these waiting people will throw timeout exception into his pants. Deferring the IO operation is dangerous thing.
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.
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 a lot for this explanation! you are awesome!
You are welcome.
very very tributary illustration. great video. the idea of mutex and semaphore really come to me translucid now
thanks for the video, now I understand better
Welcome to the channel
your voice is not audible loudly so,you better give some time on it while making vidios
with no coding examples this video is absolutely useless.
very useful...Thanks
Very clear explanation. Thanks!
Very good explanation! Crisp and clean .
thanks
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.
i found the speaker went faster and faster near the end and f
ound it hard to understand
Very clear and easy to follow explanation, thank you!
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.
Thank you very clear was useful
Very good explanation. Loved it.
Watching this for tomorrow interview
Appreciate for your explanation!
Best explanation ever
sounds like homie is laughin at his example hehehe
best explanation i have ever seen
awesome toilet example, i clearly understood
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.
Now i clearly understand. Thank you sir
glad to know that :-)
very nice expiation..Thank you..
muchisimas gracias.. me quedo bien claro...gracias a ud
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.
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
Still very good explanation that made me understand, thank you
these toilets must have gold basins,commodes,taps and stuff that is why they got keys
For the semaphore, if all the keys are identical what's to stop a person opening an occupied toilet door?
Great video very clear
This was a great explanation, thanks!
Very very nice explanation
thankyou sir for this video
Me thinking coding multiplayer is hard
Multithreading has entered the chat😅
5:43 is it comparing if it is equal to zero not less than ..?
believe or not your bathroom analogy helped me understood and finished my homework! Thank you so much.
You had me at 'toilet'
Thanks buddy for the informative video!
what software did you use to do the animation?
This is simple PowerPoint presentation
Wonderful explanation. Thank you! :)
Very very well method
Is binary semaphore and mutex same???
Thank you for the video!
what about P(mutex)V(mutex)? Does the semaphore now have ownership issues?
Watch in 1.25x
good explanation. Thanks..
very well explained
dude, you are a genius to use the toilet and key as the metaphor here.
So isn't mutex just a special case of a semaphore?
Good example.
Actually binary semaphore is one type of mutex
great Video!
Excellent presentation.
lots of toilets
Good tutorial
What? Toilet example is funny one, Good explanation...
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
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.
Beautiful explanation! I always had trouble understanding semaphores intuitively until you provided the brilliant bathroom key analogy!!
Thank you Raja, I understand now.
Thank U