And now you shall never forget what semaphores are and how they work and what they do 😎 But... there are trade-offs if you are using semaphore and for that, you need to check out the other two videos on semaphore i.e priority inversion and deadlocks (Note: you will love the example in deadlocks too as that example is something that has happened in real 😂😂)
Thanks Ravi Sir, you are great ,Now I understand about semaphore and also can implement in my own project in an easy way where I need this. Best example railway platform for semaphore .. Really thanks from my deep heart. :)))
Thank you Mayur, making ppt takes most of the time am glad these animations were helpful. Plz feel free to ask questions and do share the channel with your iOS group
I am 3:27 when writing comment. OMG This was soo amazing explanation on semaphore. I studied this in University, other UA-cam videos but Never understand this much as in this video. Man you are doing the amazing job. Keep it up.
Hey Swathi, welcome to the channel. On semaphore there are two more videos discussing about their drawbacks and in one of the video am assuming that’s the priority inversion video there’s a small section which shows the difference between them, do checkout that video and let me know if that was helpful or you need a more detailed explanation between them Priority inversion video link: ua-cam.com/video/9vRZYD0yE9A/v-deo.html
hello Ravi, thanks for this wonderful video. Ravi kya aap bata sakte ho log Alamofire ki file mein aisa kaunsa change kr dete hai jo wo uska updated version install krne se mana kr dete hai? Apne URLsession ke through bht sahi videos banai hai for API calling. If you get time then please make some videos on Alamofire also.
Hey Akanksha, welcome to the channel. Swift mai itne changes hue hai ki ab alamofire jaisi library use karna sahi nahi hai, Aisa nahi hai ki alamofire mai koi issues hai but jo cheez swift mai do chaar line mai ho sakti hai uske liye ek third party kyu add karna. So meri maano to agar aap sirf API calls kar rahe ho to alamofire ko uninstall kar do and use pure swift solution
Great tutorial, with great example :) , however I got a doubt, in one of your earlier tutorial. We resolve this type of race condition through Lock and Unlock. So Why we use Semaphore here for the same.? Does semaphore only use to make sure the accessibility of shared resource to be free or busy to different threads or they could do something more?
Welcome to the channel Adnan, Semaphores are locks to begin with, they handle race conditions more effectively than locks in general so its a wise idea to use semaphores when you have shared resources where multiple threads will try and access a single resource, locks are effective but I would not use them in a multi-threaded environment as they are not as effective as semaphores.
I'm old one in this channel, however didn't comment usually 🤣. By the way thanks for clearing the doubts... Keep it up brother. Nice channel with great content. 👍
when to use NSLock(), .lock() , .unlock()? The only usage of `semaphore` over `NSLock`, I can see is; if we require to allow more than 1 concurrent thread to access resource. Correct if I am wrong.
Hi Ravi , i am not clear about the value here. can you please help me to understand if i pass 0 or greater than 1 into value, what will happen. "let semaphore = DispatchSemaphore(value:1) "
Its used by semaphore to keep a track of which thread it signals, the implementation details of how it uses that value is far more complex, the value always has to be greater than zero.
When I started to watch your video then I have only 8month of experience in an iOS and also like fresher and salary like only 13k but after few month I got good opportunity in June 2020 with the help of your videos and now I am working as a Sr. iOS devloper and salary is 40+ and also good knowledge of an iOS , I also guide trainee and fresher in my company .Ravi sir I want send gift pls share your address. :))
Your success is the only gift that makes me happy Mandeep. Just make sure you write clean code and test cases in your project and avoid being a creative developer :)
@@CodeCat15 I watched your all video sir, total = 70video , per day 4video :)) thats wy I am confident in an iOS and also write clean code and before write any code , I think about code why I write and what I need to perform.
Can you share a video of comparing of dispatch semaphore and dispatch barrier? Because dispatch barrier is also been used to counter race condition for shared resource. I think this can be a good topic for next video.
You could but what would be the real use case of it? I suggest using semaphore.signal in your code at the right place and at the right time than relying on defer.
In the race condition example in the video, where the code was following 👇 Banking { your output comes out to be however if I run the above program many times, it give the following output some times
If u use concurrent queue..both will access balance at same time..But if u use semphore it wont be accessed at the same time ryt. So y to use concurrent queue?
The concurrent queue was shown as an example to create and demonstrate a race condition let me know if that answers your question and if not please ask more question
In real time examples you will come across to perform task asynchronously on concurrent queues, because that make your execution more fast and utilise the threads associated with it, and while doing so they try so use a resource on shared bases and make it corrupt.
It depends on how busy the system is, you may want to write few performance tests to see which process is actually taking most of the time and see if that can be improved
Since I found your channel literally I have stopped watching any other channels except let's Build that App. Thanks man
Welcome to the channel Sandip, I am glad these videos are helpful 😊
You are doing really good. The example of trains and platform is epic. 👍🏼
Thanks Chetan 👍
Sidhi baat Bhai......
itna acha koi ni samjhata . 😊
Train example is excellent 👌
Thanks Vamsi
You're doing good work. Keep doing. People like me depend upon people like you.
Thanks.
In love with the Railway Engineer Concept ❤️
And now you shall never forget what semaphores are and how they work and what they do 😎 But... there are trade-offs if you are using semaphore and for that, you need to check out the other two videos on semaphore i.e priority inversion and deadlocks (Note: you will love the example in deadlocks too as that example is something that has happened in real 😂😂)
Thanks Ravi Sir, you are great ,Now I understand about semaphore and also can implement in my own project in an easy way where I need this. Best example railway platform for semaphore .. Really thanks from my deep heart. :)))
Great works Sir, With the help of your videos, I have been able to crack Accenture's interview. Waiting for Deadlock & Priority inversion videos.
Congratulations on clearing the interview Gurinder, wishing you more success in the coming days
@@CodeCat15 Thanks Sir.
Great explanation with the awesome animation and example.
Thank you Mayur, making ppt takes most of the time am glad these animations were helpful. Plz feel free to ask questions and do share the channel with your iOS group
I am 3:27 when writing comment. OMG This was soo amazing explanation on semaphore. I studied this in University, other UA-cam videos but Never understand this much as in this video. Man you are doing the amazing job. Keep it up.
Thank you 🙏 I am glad this was helpful to you, do share it with your iOS group if you find the contents helpful
Sure
Ravi you make things so easy... great going.
Thanks Rishabh
Very helpful with great example
Glad it was helpful!
Great example for explaining the semaphore concept in simple terms. Keep it up the great work👍
Thanks, I am glad you this video was helpful, please feel free to ask questions and do share the video with your iOS group.
Great video sir, all confusion cleared
That’s awesome Paresh, do share the video with your iOS group and feel free to ask questions
good work ravi .
Superb explanation.
Thank you 🙂
Great Explanation Ravi, But can you please do the video of difference between dispatch Semaphore and dispatch group
Hey Swathi, welcome to the channel. On semaphore there are two more videos discussing about their drawbacks and in one of the video am assuming that’s the priority inversion video there’s a small section which shows the difference between them, do checkout that video and let me know if that was helpful or you need a more detailed explanation between them
Priority inversion video link: ua-cam.com/video/9vRZYD0yE9A/v-deo.html
hello Ravi, thanks for this wonderful video.
Ravi kya aap bata sakte ho log Alamofire ki file mein aisa kaunsa change kr dete hai jo wo uska updated version install krne se mana kr dete hai?
Apne URLsession ke through bht sahi videos banai hai for API calling. If you get time then please make some videos on Alamofire also.
Hey Akanksha, welcome to the channel. Swift mai itne changes hue hai ki ab alamofire jaisi library use karna sahi nahi hai, Aisa nahi hai ki alamofire mai koi issues hai but jo cheez swift mai do chaar line mai ho sakti hai uske liye ek third party kyu add karna. So meri maano to agar aap sirf API calls kar rahe ho to alamofire ko uninstall kar do and use pure swift solution
Great job!
Ravi sir, Pls make video on socket , if possible bcz socket type video will help me and other developer who struggle with socket
After the threading series, I will surely look into other topics thanks for the video suggestion Mandeep
very good explanation
Great video
glad it was helpful Lalit
thanks you big fan
Great Buddy.
Great tutorial, with great example :) , however I got a doubt, in one of your earlier tutorial. We resolve this type of race condition through Lock and Unlock. So Why we use Semaphore here for the same.? Does semaphore only use to make sure the accessibility of shared resource to be free or busy to different threads or they could do something more?
Welcome to the channel Adnan, Semaphores are locks to begin with, they handle race conditions more effectively than locks in general so its a wise idea to use semaphores when you have shared resources where multiple threads will try and access a single resource, locks are effective but I would not use them in a multi-threaded environment as they are not as effective as semaphores.
I'm old one in this channel, however didn't comment usually 🤣. By the way thanks for clearing the doubts... Keep it up brother. Nice channel with great content. 👍
when to use NSLock(), .lock() , .unlock()? The only usage of `semaphore` over `NSLock`, I can see is; if we require to allow more than 1 concurrent thread to access resource. Correct if I am wrong.
Hi Ravi , i am not clear about the value here. can you please help me to understand if i pass 0 or greater than 1 into value, what will happen.
"let semaphore = DispatchSemaphore(value:1) "
Its used by semaphore to keep a track of which thread it signals, the implementation details of how it uses that value is far more complex, the value always has to be greater than zero.
Is Dispatch Barrier the same because I tried the same example it's giving negative balance
Instead of inside the queue tasks, even better to use Semaphores inside method withdrawAmount() of structs ATM and Bank.
When I started to watch your video then I have only 8month of experience in an iOS and also like fresher and salary like only 13k but after few month I got good opportunity in June 2020 with the help of your videos and now I am working as a Sr. iOS devloper and salary is 40+ and also good knowledge of an iOS , I also guide trainee and fresher in my company .Ravi sir I want send gift pls share your address. :))
Your success is the only gift that makes me happy Mandeep. Just make sure you write clean code and test cases in your project and avoid being a creative developer :)
@@CodeCat15 I watched your all video sir, total = 70video , per day 4video :)) thats wy I am confident in an iOS and also write clean code and before write any code , I think about code why I write and what I need to perform.
Can you share a video of comparing of dispatch semaphore and dispatch barrier? Because dispatch barrier is also been used to counter race condition for shared resource. I think this can be a good topic for next video.
Yes, I will once I complete deadlock and priority inversion videos, thank you for the video request
can we use defer for semaphore.signal() ?
You could but what would be the real use case of it? I suggest using semaphore.signal in your code at the right place and at the right time than relying on defer.
I tried it by removing Thread.sleep() and without semaphore, it gives same results as by using semaphore. can't understand why 🤔
In the race condition example in the video, where the code was following 👇
Banking {
your output comes out to be
however if I run the above program many times, it give the following output some times
If u use concurrent queue..both will access balance at same time..But if u use semphore it wont be accessed at the same time ryt. So y to use concurrent queue?
The concurrent queue was shown as an example to create and demonstrate a race condition let me know if that answers your question and if not please ask more question
In real time examples you will come across to perform task asynchronously on concurrent queues, because that make your execution more fast and utilise the threads associated with it, and while doing so they try so use a resource on shared bases and make it corrupt.
You explained it perfectly Chetan
When we use semaphore it makes our process slow.
It depends on how busy the system is, you may want to write few performance tests to see which process is actually taking most of the time and see if that can be improved