Multithreading | Lock Free Programming | HFT Quant Interview

Поділитися
Вставка
  • Опубліковано 24 сер 2024
  • Discussed solution to multithreading question asked in HFT Quant Interview which has to be solved using lock free programming.
    Implemented in C++17
    Connect with me on Instagram: / shubham__cr7

КОМЕНТАРІ • 19

  • @CodingInterviewPrep
    @CodingInterviewPrep  Рік тому +4

    ignore the sound of AC in background. Didn’t realise that it was so loud. Apologies 🙏

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

      The AC noise is not an issue, Great Content!
      Just one question - Why write lock-free programs? What is the use case here?

  • @TheJocadasa
    @TheJocadasa Рік тому +7

    Doesn't using std::atomic to synchronize like this resemble a spinlock? Can that trully be called lock-free?
    With a large number of threads, the likelihood of the running thread being the correct one is low. So wouldn't it be more prudent to use blocking primitives like semaphores/condition variables?
    On another note, since we continuously spin and will eventually read the updated value, can't we use a non-thread-safe integer instead of std::atomic in this scenario?

    • @abhi-5783
      @abhi-5783 3 місяці тому

      No, using std atomic ensure sequential consistency, which ensures that the compiler doesn’t do reordering or read old cached value.

    • @TheJocadasa
      @TheJocadasa 3 місяці тому +1

      ​@@abhi-5783 I understand now that we can't use a non-thread-safe integer because of UB. The memory ordering also ensures the proper value of `currIndex` is read.
      However, I still don't understand how this "lock-free" approach makes any sense in this scenario. Especially if we are expecting a large number of threads, or we are doing slow operations like writing to and flushing std::cout. Isn't this just a bad use-case for atomics?

  • @raunaquepatra3966
    @raunaquepatra3966 19 днів тому

    the while loop is technically a lock

  • @sarathiprabu
    @sarathiprabu Рік тому +1

    Thank you. Your approach and code is clean and elegant. Please create similar videos like this whenever you get time...

  • @akshatsharma9527
    @akshatsharma9527 Рік тому +1

    Shubham I always enjoy your videos quite informative being a SDE still lots of Things i have to learn concurrency ,,, Great

  • @nishankverma7655
    @nishankverma7655 Місяць тому

    I've a question is it ok to use global variables while using this programming techniques

  • @eddanapudir
    @eddanapudir 9 місяців тому

    This is very useful. Thank you very much. May I request you to post a video on ‘how market data handlers work and update order book in HFT firms’ please? Thanks

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

    yes please post videos regularly

  • @abh9789
    @abh9789 Рік тому +2

    Bhaiya, I would be highly grateful if you can kindly advise that, in your genuine experience, do ranks on competitive programming profiles help in getting shortlisted for interview?? Even as Candidate Master in Codeforces or 6* in CC... I'm nit grad this year, but asking in respect of off campus & not particularly for hfts. Thanks bhaiya immensely!🙏🙏

    • @liquidmetal718
      @liquidmetal718 11 місяців тому

      Unless you prove yourself in those coding rounds or hackathons - conducted by companies, no one would care about your ranks. This is not like JEE Advanced exams, where people get selected based on ranks.

  • @nachiketkanore
    @nachiketkanore Рік тому +1

    I don't understand why multithreading is relevant for this problem. Only one thread is doing work at a particular time, while others are waiting for their turn. For learning purposes, it is fine but it would be better if a real use case is chosen.

    • @CodingInterviewPrep
      @CodingInterviewPrep  Рік тому +2

      these kind of questions are asked to check if a candidate knows about thread synchronization and is able to implement it. These concepts are very useful in systems which utilises the pipeline architecture for very high throughout, where the output of nth thread is input to (n+1)th thread.

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

    Bhai what would be chances of getting selected in hft for CP vs Non CP but good skills