Mutex is a object owned by thread who is executing in critical section whereas semaphore is a signaling mechanism.
Пікірлер: 232
@whatdoyousay42365 жыл бұрын
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.
@rishkum5365 жыл бұрын
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.
@totommymmy5 жыл бұрын
Thank you so much! The toilet is such a good example for memorizing and understanding!
@pepe66664 жыл бұрын
it actually really is.
@uzairghole30252 ай бұрын
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.
@burhanmuhyiddin43724 жыл бұрын
Thank you very much :) I also confused about the difference between mutexes and semaphores and you explained the difference very clearly.
@tedz2usa Жыл бұрын
Beautiful explanation! I always had trouble understanding semaphores intuitively until you provided the brilliant bathroom key analogy!!
@TheLPfunnTV2 жыл бұрын
You might have just saved my exams grade! I understood the explanation with the metaphore so much better and it sticks. Thank you!
@omargamal2148 Жыл бұрын
don't think there's any saving if you call it a metaphore
@TheLPfunnTV Жыл бұрын
@@omargamal2148 good one!
@majidsaeidi776027 күн бұрын
most clearly example to know mutex and semaphore. Thanks
@camelcase93103 жыл бұрын
believe or not your bathroom analogy helped me understood and finished my homework! Thank you so much.
@MultiShiv197 жыл бұрын
Watch at 1.25x speed
@shivangikansal80257 жыл бұрын
me too :D
@basantachaulagain61046 жыл бұрын
1.5x works fine for me
@Darieee6 жыл бұрын
I watched this at 20x guys .. I think I win
@omairbhore6 жыл бұрын
I darieee you to watch it in 40x
@BloodHaZaRd6665 жыл бұрын
1.25 almost english, at 2 becomes japanese
@SportsIncorporated6 жыл бұрын
Great explanation. Made it all simple. For someone without a computer science degree, me.
@nishantchauhan15485 жыл бұрын
Of all possible examples in the world, you chose a toilet...
@weirdopersonnal5 жыл бұрын
hahahaha!
@justaninfiredperson5 жыл бұрын
Nishant Chauhan 😂
@Teslacoil334 жыл бұрын
Lock(mutex) "Do Work" Unlock(mutex)
@mariumahmed45674 жыл бұрын
😂😂😂😂👏🏻👏🏻
@shovon94124 жыл бұрын
Of all examples the toilet will probably be most memorable
@notoppland Жыл бұрын
Very clear and easy to follow explanation, thank you!
@ifxzrvz17064 жыл бұрын
thank you, your explanation is one of the best.
@saadmanahmed8603 жыл бұрын
very very tributary illustration. great video. the idea of mutex and semaphore really come to me translucid now
@payalsagar18084 жыл бұрын
honestly thankyou so much for this perfect example☺.... the concept got cleared
@dboothe78893 жыл бұрын
Great work! I now understand the difference the night before my exam. Many thanks Sir!
@SubcribetoTin7 жыл бұрын
Thanks! Simple and straight to the point.
@HowTomakeitdone7 жыл бұрын
thanks welcome to the channel.
@lmnefg1213 жыл бұрын
dude, you are a genius to use the toilet and key as the metaphor here.
@seba_duran7 жыл бұрын
thanks for the video, now I understand better
@HowTomakeitdone7 жыл бұрын
Welcome to the channel
@pepe66664 жыл бұрын
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
@Shifter210007 жыл бұрын
Very good explanation! Crisp and clean .
@HowTomakeitdone7 жыл бұрын
thanks
@sureshkumarkaushik61097 жыл бұрын
Thanks for this video and it helps us to understand the main concepts in best way. and easy to remember the conepts.
@HowTomakeitdone7 жыл бұрын
Thanks Welcome to the channel.
@medhm22625 жыл бұрын
My frend its nice exemple it will stell in my memory for ever tanks
@sent4dc7 жыл бұрын
All I could understand is "toilet."
@PK-xe6sm6 жыл бұрын
A few times during this video I've been wondering if he did still use English
@unknownuser61435 жыл бұрын
sent4dc 😂😂😂😂
@nishik3325 жыл бұрын
Did u pass in the exam
@badger64313 жыл бұрын
Because you are full of s-hit.
@XEQTIONRZ7 жыл бұрын
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.
@muhammadwasif8817 жыл бұрын
In implementation Mutex generates busy wait and starvation so I think he is right..!
@muhammadwasif8817 жыл бұрын
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
@wildglorypsn7 жыл бұрын
not necessarily...starvation doesn't happen often.
@subhashishsen61575 жыл бұрын
use mutex_try_lock() instead of mutex_lock()
@daisysunshine66064 жыл бұрын
thanks for the explanation i was confused
@Penguinsxz8 жыл бұрын
Thanks for the awesome review!
@HowTomakeitdone8 жыл бұрын
welcome to the channel.
@jonathanazzopardipaul50483 жыл бұрын
This was a great explanation, thanks!
@pengxiaohan33712 жыл бұрын
Very clear explanation. Thanks!
@047gauravkumartiwari5 Жыл бұрын
A clear and lucid explanation!
@arthurimona59015 жыл бұрын
Thanks buddy for the informative video!
8 жыл бұрын
Very Good.Keep it up :)
@HowTomakeitdone8 жыл бұрын
Welcome to channel.
@sumitkaushik19426 жыл бұрын
HowTo सपना
@andresperez46987 жыл бұрын
muchisimas gracias.. me quedo bien claro...gracias a ud
@suyashvishnoi61576 жыл бұрын
Now i clearly understand. Thank you sir
@HowTomakeitdone6 жыл бұрын
glad to know that :-)
@kevinfernandez22695 жыл бұрын
He probably went to a dollar general where you have to get a key from the register for the bathroom.
@Teslacoil334 жыл бұрын
For the semaphore, if all the keys are identical what's to stop a person opening an occupied toilet door?
@killstriker645 жыл бұрын
thanks a lot for this explanation! you are awesome!
@HowTomakeitdone5 жыл бұрын
You are welcome.
@wilsonfarias92486 жыл бұрын
Thank you for the video!
@kartikpodugu7 ай бұрын
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.
@TL-fe9si5 жыл бұрын
what about P(mutex)V(mutex)? Does the semaphore now have ownership issues?
@CoreDump451 Жыл бұрын
Wonderful explanation. Thank you! :)
@TellaTrix11 ай бұрын
Appreciate for your explanation!
@Light-th1co6 жыл бұрын
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.
@shrimatkapoor22003 жыл бұрын
I still don't understand if the keys are identical, couldn't two threads access the same object and cause a race condition?
@OlliS715 ай бұрын
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.
@anikettiwari68855 жыл бұрын
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
@prithvisinh6 жыл бұрын
Excellent presentation.
@paulohanded286 жыл бұрын
what software did you use to do the animation?
@HowTomakeitdone6 жыл бұрын
This is simple PowerPoint presentation
@ameyzulkanthiwar91486 жыл бұрын
very nice expiation..Thank you..
@MinhTran-sl7kc4 жыл бұрын
Thank you Raja, I understand now.
@adharshmohan92496 жыл бұрын
good explanation. Thanks..
@wssz1126 жыл бұрын
love that pictures!!!!! thank you
@peimanfarshbaf75224 жыл бұрын
best explanation i have ever seen
@vivekthakkar52765 жыл бұрын
How can someone dislike this video?
@aizazulhaq47024 жыл бұрын
Yeah sure... cz there is a toilet in the video as an example.. duhhh
@zhengrui3154 жыл бұрын
I really like this toilet, sorry i mean tutorial
@zhengrui3153 жыл бұрын
@@blazkowicz666 seriously? you are picking a fight over this comment? I have no idea why it's offending to you
@blazkowicz6663 жыл бұрын
@@zhengrui315 I thought that was something Racist implied before I watched the video. I have deleted the comment 🤝
@UdayKumar-zm4ft3 жыл бұрын
🤣🤣🤣
@akhilkandibanda7 жыл бұрын
awesome toilet example, i clearly understood
@gaborm47672 жыл бұрын
What is the benefit of mutex over semaphore?
@jeyko6664 жыл бұрын
10/10, indian enough that it was a good tutorial!
@a2zuser15 жыл бұрын
Thank you very clear was useful
@enkr1 Жыл бұрын
5:43 is it comparing if it is equal to zero not less than ..?
@michaelcrainiciuc Жыл бұрын
Still very good explanation that made me understand, thank you
@shovon94124 жыл бұрын
Great video very clear
@kuroketanItem8 жыл бұрын
thanks man , great example and explanation :thumb_up:
@HowTomakeitdone7 жыл бұрын
Thank you and welcome to the channel
@zxuiji2 жыл бұрын
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 ); } ```
@baqtronic77045 жыл бұрын
Seems a good explanation, but I struggled very hard to understand this english... Subtitles would be very nice (not automatic...)
@daisysunshine66064 жыл бұрын
is english your second language? maybe thats why it was hard.
@warrenpeterson5709 Жыл бұрын
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.
@anilkinikar3 жыл бұрын
Very good explanation.
@mujjumaaz20087 жыл бұрын
Easily understood.
@loinguyen.youtube7 жыл бұрын
Thank you thank you so much!
@HowTomakeitdone7 жыл бұрын
you are welcome.
@bluesteel13 жыл бұрын
Very very nice explanation
@amithstark89465 ай бұрын
very well explained
@bharat_india12 Жыл бұрын
Watching this for tomorrow interview
@jammy20034 жыл бұрын
Thanks so much!
@rtm00764 жыл бұрын
Best explanation ever
@abhirajtyagi9244 Жыл бұрын
thankyou sir for this video
@matthiaswolf2288 Жыл бұрын
great Video!
@SriLakshmi33957 жыл бұрын
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.. :-)
@HowTomakeitdone7 жыл бұрын
Thanks for nice comment It's really great.
@unknownuser61435 жыл бұрын
Good tutorial
@koti571bulasara47 жыл бұрын
good explanation
@pavanisivadath98137 жыл бұрын
good work in making the pictures
@HowTomakeitdone7 жыл бұрын
thanks Welcome to the channel.
@rogerzheng28144 жыл бұрын
So isn't mutex just a special case of a semaphore?
@rajattandon56922 жыл бұрын
Great explanation
@DEV-gz3nk6 жыл бұрын
what is mutex datatype
@fatemakhalfan69803 жыл бұрын
very useful...Thanks
@Iamnoone562 жыл бұрын
bhut umdaa
@tanaygupta6323 жыл бұрын
I want difference between mutex and binary semaphore.
@harshapalanki54913 жыл бұрын
Is binary semaphore and mutex same???
@mywtfmp38 жыл бұрын
Very good. But I think you need to explain why mutex use ownership while semaphore use signaling mechanism.
@HowTomakeitdone8 жыл бұрын
+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.
@AhmadKhanNaul14 жыл бұрын
Very very well method
@poojasingh-nw3mv7 жыл бұрын
thanks for the video.....
@HowTomakeitdone7 жыл бұрын
Thanx for appreciating
@openyourmind16943 жыл бұрын
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
@voipims7 жыл бұрын
This video is half....people do have confusion between mutex and binary semaphore
@farruhhabibullaev53165 жыл бұрын
What? Toilet example is funny one, Good explanation...
@afraimlevi98713 жыл бұрын
Thank U
@lavanyabellamkonda73997 жыл бұрын
nice video.thank you
@HowTomakeitdone7 жыл бұрын
thanks
@ibknl19864 жыл бұрын
Good example.
@teuton83637 жыл бұрын
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.
@HowTomakeitdone7 жыл бұрын
thanks for your concern. I will improve audio definitely.
@KNT_197 жыл бұрын
In case of semaphore, if the two threads accessing a shared resource, there will be race condition. Can tell, in this case, how synchronization is achieved?
@HowTomakeitdone7 жыл бұрын
If you want only one resource to be accessed at one time then you need to take semaphore value accordingly.
@gauravhiran67475 жыл бұрын
Use java "synchronised" keyword.
@ashishchauhan84946 жыл бұрын
Thanks for video
@HowTomakeitdone6 жыл бұрын
you are welcome Ashish.
@blockobutter3 жыл бұрын
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.
@Mohammed-fk9dj6 жыл бұрын
4 identical keys for the toilet!!! what if somebody already in toilet and another person come and open the toilet! LOL
@petermako31745 жыл бұрын
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