Dispatch semaphore and race conditions in Swift Hindi tutorial

Поділитися
Вставка
  • Опубліковано 7 жов 2024

КОМЕНТАРІ • 65

  • @sandipkhedkar
    @sandipkhedkar 3 роки тому +3

    Since I found your channel literally I have stopped watching any other channels except let's Build that App. Thanks man

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Welcome to the channel Sandip, I am glad these videos are helpful 😊

  • @chetanaggarwal119
    @chetanaggarwal119 3 роки тому +5

    You are doing really good. The example of trains and platform is epic. 👍🏼

  • @RohitSharma-xu5tn
    @RohitSharma-xu5tn 2 роки тому

    Sidhi baat Bhai......
    itna acha koi ni samjhata . 😊

  • @vamsi3877
    @vamsi3877 3 роки тому +2

    Train example is excellent 👌

  • @mansapratapsingh417
    @mansapratapsingh417 3 роки тому

    You're doing good work. Keep doing. People like me depend upon people like you.
    Thanks.

  • @darshantelang1535
    @darshantelang1535 3 роки тому +1

    In love with the Railway Engineer Concept ❤️

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      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 😂😂)

  • @MandeepSingh-ly3jj
    @MandeepSingh-ly3jj 3 роки тому +1

    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. :)))

  • @GurinderBatth
    @GurinderBatth 3 роки тому +5

    Great works Sir, With the help of your videos, I have been able to crack Accenture's interview. Waiting for Deadlock & Priority inversion videos.

    • @CodeCat15
      @CodeCat15  3 роки тому +3

      Congratulations on clearing the interview Gurinder, wishing you more success in the coming days

    • @GurinderBatth
      @GurinderBatth 3 роки тому +1

      @@CodeCat15 Thanks Sir.

  • @mayur.bendale
    @mayur.bendale 3 роки тому +1

    Great explanation with the awesome animation and example.

    • @CodeCat15
      @CodeCat15  2 роки тому +1

      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

  • @afaaqahmedsaqi
    @afaaqahmedsaqi 3 роки тому +1

    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.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Thank you 🙏 I am glad this was helpful to you, do share it with your iOS group if you find the contents helpful

    • @afaaqahmedsaqi
      @afaaqahmedsaqi 3 роки тому

      Sure

  • @rishabhsrivastava9849
    @rishabhsrivastava9849 3 роки тому +1

    Ravi you make things so easy... great going.

  • @DhavalHNena
    @DhavalHNena 2 роки тому +1

    Very helpful with great example

  • @nikunjazilen3095
    @nikunjazilen3095 Рік тому

    Great example for explaining the semaphore concept in simple terms. Keep it up the great work👍

    • @CodeCat15
      @CodeCat15  Рік тому

      Thanks, I am glad you this video was helpful, please feel free to ask questions and do share the video with your iOS group.

  • @paresh6371
    @paresh6371 3 роки тому +1

    Great video sir, all confusion cleared

    • @CodeCat15
      @CodeCat15  3 роки тому

      That’s awesome Paresh, do share the video with your iOS group and feel free to ask questions

  • @akshaykumar-qj2kx
    @akshaykumar-qj2kx 3 роки тому +1

    good work ravi .

  • @pushpraj7329
    @pushpraj7329 3 роки тому +1

    Superb explanation.

  • @swathitata3240
    @swathitata3240 3 роки тому +1

    Great Explanation Ravi, But can you please do the video of difference between dispatch Semaphore and dispatch group

    • @CodeCat15
      @CodeCat15  3 роки тому

      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

  • @akanksha2143
    @akanksha2143 3 роки тому +1

    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.

    • @CodeCat15
      @CodeCat15  3 роки тому

      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

  • @purushottamkumarverma4811
    @purushottamkumarverma4811 3 роки тому +1

    Great job!

  • @MandeepSingh-ly3jj
    @MandeepSingh-ly3jj 3 роки тому +1

    Ravi sir, Pls make video on socket , if possible bcz socket type video will help me and other developer who struggle with socket

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      After the threading series, I will surely look into other topics thanks for the video suggestion Mandeep

  • @mahesh1398
    @mahesh1398 2 роки тому

    very good explanation

  • @lalitsharma9969
    @lalitsharma9969 3 роки тому +1

    Great video

    • @CodeCat15
      @CodeCat15  3 роки тому

      glad it was helpful Lalit

  • @riffatkhan6006
    @riffatkhan6006 Рік тому

    thanks you big fan

  • @vidhanshubhardwaj9978
    @vidhanshubhardwaj9978 3 роки тому

    Great Buddy.

  • @AdnanKhan-ug1qn
    @AdnanKhan-ug1qn 3 роки тому +1

    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?

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      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.

    • @AdnanKhan-ug1qn
      @AdnanKhan-ug1qn 3 роки тому

      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. 👍

  • @mazedar_tv
    @mazedar_tv 2 роки тому

    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.

  • @RajeshSharmaIndia
    @RajeshSharmaIndia 3 роки тому +1

    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) "

    • @CodeCat15
      @CodeCat15  3 роки тому

      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.

  • @salmansiddiqui9522
    @salmansiddiqui9522 3 роки тому

    Is Dispatch Barrier the same because I tried the same example it's giving negative balance

  • @souravdeb6126
    @souravdeb6126 3 роки тому

    Instead of inside the queue tasks, even better to use Semaphores inside method withdrawAmount() of structs ATM and Bank.

  • @MandeepSingh-ly3jj
    @MandeepSingh-ly3jj 3 роки тому +1

    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. :))

    • @CodeCat15
      @CodeCat15  3 роки тому +2

      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 :)

    • @MandeepSingh-ly3jj
      @MandeepSingh-ly3jj 3 роки тому +1

      @@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.

  • @chetanaggarwal119
    @chetanaggarwal119 3 роки тому +1

    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.

    • @CodeCat15
      @CodeCat15  3 роки тому

      Yes, I will once I complete deadlock and priority inversion videos, thank you for the video request

  • @rahulparikh6925
    @rahulparikh6925 7 місяців тому +1

    can we use defer for semaphore.signal() ?

    • @CodeCat15
      @CodeCat15  7 місяців тому

      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.

  • @AbdulRehman-nj2ph
    @AbdulRehman-nj2ph Рік тому

    I tried it by removing Thread.sleep() and without semaphore, it gives same results as by using semaphore. can't understand why 🤔

  • @shilpeegupta5847
    @shilpeegupta5847 2 роки тому

    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

  • @Karthik-gr7ie
    @Karthik-gr7ie 3 роки тому +1

    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?

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      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

    • @chetanaggarwal119
      @chetanaggarwal119 3 роки тому +2

      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.

    • @CodeCat15
      @CodeCat15  3 роки тому

      You explained it perfectly Chetan

  • @asherazeem3282
    @asherazeem3282 2 роки тому +1

    When we use semaphore it makes our process slow.

    • @CodeCat15
      @CodeCat15  2 роки тому

      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