Mutex In C++

Поделиться
HTML-код
  • Опубликовано: 15 июн 2019
  • JOIN ME
    -----
    RUclips 🎬 / @cppnuts
    Patreon 🚀 / cppnuts
    COMPLETE PLAYLIST
    ------------
    C++ Tutorial For Beginners: • Introduction To C++
    STL (Standard Template Library): • STL In C++
    ThreadIng In C++: • Multithreading In C++
    Data Structures: • Data Structure
    Algorithms: • Binary Search
    Design Patterns: • Factory Design Pattern...
    Smart Pointers: • Smart Pointer In C++
    C++14: • Digit Separator In C++
    C++17: • std string_view in C++...
    C++ All Type Casts: • static_cast In C++
    INTERVIEW PLAYLIST
    ------------
    C++ Interview Q&A: • Structural Padding & P...
    C++ Interview Q&A For Experienced: • How delete[] Knows How...
    Linked List Interview Questions: • Find Kth Node From Bac...
    BST Interview Questions: • Search Element In Bina...
    Array Interview Questions: • Reverse An Array
    String Interview Questions: • Check String Is Palind...
    Bit Manipulation Questions: • Find Set Bit In Intege...
    Binary Tree Interview Question: • Invert Binary Tree
    Sorting Algorithms: • Bubble Sort
    C++ MCQ: • Video
    C MCQ: • What printf returns af...
    C Interview Questions: • Designated Initializat...
    QUICK SHORT VIDEOS
    -------------
    C++ Short : • C++ Short Videos
    C Short : • Shorts C Programming MCQ
    In this video we will learn about Mutex In C++ Threading | Why Use Mutex | What Is Race Condition And How To Solve It? | What Is Critical Section
    Mutex: Mutual Exclusion
    RACE CONDITION:
    0. Race condition is a situation where two or more threads/process happens to change a common data at the same time.
    1. If there is a race condition then we have to protect it and the protected section is called critical section/region.
    MUTEX:
    0. Mutex is used to avoid race condition.
    1. We use lock() , unlock() on mutex to avoid race condition.
    #threading #cpp #programming #tutorial #computerscience #softwareengineering

Комментарии • 221

  • @CppNuts
    @CppNuts  5 лет назад +12

    Hi everyone, Don't forget to hit LIKE and SUBSCRIBE button for more videos like this!!
    And this will help me a-lot.

  • @amber1862
    @amber1862 4 года назад +46

    British guy here; you're an amazing teacher and I can understand you very well. Brilliant content as always.

    • @CppNuts
      @CppNuts  4 года назад +11

      Thanks dude, and glad that i can help people..
      Thanks for giving this feeling..

  • @mohsenir69
    @mohsenir69 4 года назад +90

    So Mutex is like Toilet, only one person can enter and when he finished another person can enter.

    • @CppNuts
      @CppNuts  4 года назад +12

      Exactly.. 😃

    • @hsaidinsan6345
      @hsaidinsan6345 4 года назад

      😂😂😂

    • @konjitsileshi8984
      @konjitsileshi8984 4 года назад +24

      The toilet is the critical region rather. The key to the toilet is mutex.

    • @saurabhverma3453
      @saurabhverma3453 3 года назад +6

      Depends...couple may enter together, for some common interest.😂😂😂

    • @mohammedumarsheriff5801
      @mohammedumarsheriff5801 3 года назад +2

      @@saurabhverma3453 @CPPNuts needs to explain that situation now.

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 5 лет назад +19

    Best Video on Mutex concept Ever..Thanks a lot for making understading vast conepts so easy to understand..Thanks

    • @CppNuts
      @CppNuts  5 лет назад +2

      Thanks for your appreciation dude.

  • @sambrismo8981
    @sambrismo8981 2 года назад +2

    I really appreciate you giving us this content for free. Great playlist on threading. Keep going!

    • @CppNuts
      @CppNuts  2 года назад

      Welcome dude..

  • @TarunKumarSaraswat
    @TarunKumarSaraswat 3 года назад +3

    It's always fun to watch your videos, not boring at all. Keep creating such amazing informative videos

    • @CppNuts
      @CppNuts  3 года назад

      Thank you so much 😀

  • @dirtfpv
    @dirtfpv 2 года назад

    Great thorough explanation of what is a very simple concept. Well done. Thank you.

  • @mdshamshalam8925
    @mdshamshalam8925 4 года назад +5

    awesome man.... Really awesome . i just want to say need more videos on multi-threading. You started from basic but we need till depth :):) . No need to watch other videos .Really each and every topic explanation is awesome. keep it up man .

    • @CppNuts
      @CppNuts  4 года назад

      Thanks man, sure new videos will come.

  • @j_blue6784
    @j_blue6784 3 года назад +1

    Your explanation makes it very clear, thank you!

    • @CppNuts
      @CppNuts  3 года назад

      Glad it was helpful!

  • @RAHULROY-oc4ro
    @RAHULROY-oc4ro 3 года назад +1

    the best ever explaination , there is always something new to learn here. thank you so much SIR.

    • @CppNuts
      @CppNuts  3 года назад

      Thanks dude..

  • @dogunboundhounds9649
    @dogunboundhounds9649 3 года назад +1

    Great tutorial!
    Love from America

  • @pradeexsu
    @pradeexsu 4 года назад +3

    Great explanation,
    you make every topic easy for every one.
    thanks bhiya
    it help me a lot.

    • @CppNuts
      @CppNuts  4 года назад +1

      Thanks man!!

  • @giusepperandazzo5357
    @giusepperandazzo5357 2 года назад

    Great example and very easy to understand also for beginners on multithreading

  • @sagex3383
    @sagex3383 2 года назад

    These videos are amazing omg I actually got it

  • @NAYAN0ashcatchup
    @NAYAN0ashcatchup 5 лет назад +2

    thank you sir.....your videos are really very helpful in getting the concept.. keep doing the same

    • @CppNuts
      @CppNuts  5 лет назад +1

      Thanks man!!

  • @saikirantelker9995
    @saikirantelker9995 3 года назад

    Great and well optimized. Thanks for this video.

    • @CppNuts
      @CppNuts  3 года назад

      Glad you liked it!

  • @muhammedyasinhanyasar539
    @muhammedyasinhanyasar539 3 года назад

    I have subscribed. Yo dude, it is absolutely amazing!

    • @CppNuts
      @CppNuts  3 года назад

      Thanks for the sub!

  • @harounlouati6602
    @harounlouati6602 Год назад

    Thank you so much. You explained well the Mutex. Keep going on.

  • @josephstark758
    @josephstark758 5 лет назад +2

    I never thought I would find a channel like this 😳😳😳 great work

    • @CppNuts
      @CppNuts  5 лет назад

      Thanks for such a nice comment, means a lot.

    • @josephstark758
      @josephstark758 5 лет назад +1

      Can you start making c++ mini projects

    • @CppNuts
      @CppNuts  5 лет назад

      No man sorry, i hardly get time for youtube regular videos, i am not a professor, work in some company as SE.

    • @josephstark758
      @josephstark758 5 лет назад

      @@CppNuts oh never mind your tuts are great

  • @krisitak
    @krisitak 4 года назад +3

    Thank you, quality content!

    • @CppNuts
      @CppNuts  4 года назад

      Thank you so much for the comment!!

  • @amitpaunikar3408
    @amitpaunikar3408 5 лет назад +1

    After watching ur videos....no need to watch other videos.... awesome man.

    • @CppNuts
      @CppNuts  5 лет назад

      Its my pleasure, thanks for the comment man.

  • @mentalthink1
    @mentalthink1 3 года назад

    Awesome explanation like always, I love this channel.

    • @CppNuts
      @CppNuts  3 года назад

      Thanks dude..

  • @mousumidey2663
    @mousumidey2663 2 года назад +2

    Very well explained all the concepts. I have been following you from quite sometime and really grateful for the contents that you make. I have one request please could you explain about semaphores with an example in c++. I have gone through many other contents available on internet, although I have a rough idea about semaphores and its mechanism but need a good example in c++ to understand the implementation of semaphores more clearly. If you could explain this it would be a great help for me. Thanks again :)

  • @digimikeh
    @digimikeh 4 года назад +3

    Yourself are using mutex while drawing and coding ...
    I like your english too.. so...
    ++subscribed..

    • @CppNuts
      @CppNuts  4 года назад +1

      Thanks man!!

  • @priyanshvatsal9791
    @priyanshvatsal9791 11 месяцев назад

    Thanks for such an explanation ❤

  • @bhupankgoswami5709
    @bhupankgoswami5709 4 года назад +3

    Nice explanation. Please make a video on the semaphore as well.

  • @yuhaohan1451
    @yuhaohan1451 Год назад

    Thank you, very helpful!

  • @Bobby-mf6fw
    @Bobby-mf6fw 2 года назад

    Agree I m a c# developer bt watch your videos for concepts. 👍

  • @arnamaity2171
    @arnamaity2171 Год назад +1

    Great video! I do have one doubt though, using mutex we can restrict access to the critical section to a single thread at a time, but there is not guarantee as to which thread reaches the critical section first. In the example discussed in the video the order in which the threads access the critical section has no impact on the final result. But if we have situation where the order of execution of threads impacts the final result, (suppose say we are performing two different mathematical operations on the global variable on the separate threads) then how do we deal with such a situation?

  • @kartikpodugu
    @kartikpodugu 10 месяцев назад

    simple and easy to understand explanation.

  • @karabgut
    @karabgut 2 года назад

    PLEASE ADD ALL THE COMPUTER SCIENCE COURSES NEEDED, YOU'RE THE ONE THAT TEACHES BEST. I have an electrical and electronics engineering background but I am willing to learn computer science, and if you have any suggestion from your videos to start from the beginning please let me know, if you don't I am waiting to you create those videos.

    • @CppNuts
      @CppNuts  2 года назад +1

      Thanks..
      Actually there is no start and end.
      You can choose a playlists for the start, like you can go for C Tutorial PlayList and then C++ Tutorial Playlist, once you are done with these you can choose to prepare for interview of still go for data structure playlist and design pattern playlist.

  • @trilecao9014
    @trilecao9014 3 года назад

    Thanks!
    1. Race condition vs. Mutex

  • @ankan1627
    @ankan1627 4 года назад

    Great video ! Can you please tell me what tool you used for writing on the screen ? This looks very professional.

  • @workflowinmind
    @workflowinmind 4 года назад +1

    Very good one !!

  • @matheenshk
    @matheenshk 4 года назад

    This explanation was amazing with simple code .i would request you pls. post Semaphore & Spin lock. awaiting..!

  • @I_dont_like_fft
    @I_dont_like_fft 3 месяца назад

    Thanks a lot 💙

  • @glennmarkabalos6657
    @glennmarkabalos6657 3 года назад

    sir, you're really a great teacher. thanks a lot.

    • @CppNuts
      @CppNuts  3 года назад

      Thanks man..

  • @Hugo_Musk
    @Hugo_Musk 8 месяцев назад

    Love this video~! Thanks:)

    • @CppNuts
      @CppNuts  8 месяцев назад

      Glad you enjoyed it!

  • @RAMANKUMAR-xl4pr
    @RAMANKUMAR-xl4pr 4 года назад +2

    Thanks Lot Dear, I was waiting for c++11 for long time. Your attitude is so impressive . Can you plz make a video How mutex is failed to handle more than two thread .

    • @CppNuts
      @CppNuts  4 года назад

      Hi Raman, thanks for the comment but i am not able to understand why mutex will fail to handle more than two threads??
      It is actually meant for more than 1 thread.

  • @suman-majhi
    @suman-majhi 3 года назад +1

    One thing which I don't understand here, why people are disliking this video?🤦‍♂️🤦‍♂️

  • @andreamia629
    @andreamia629 4 года назад +1

    i duno why ppl are disliking... explained very well thank u

  • @EddieMasseyIII
    @EddieMasseyIII 2 года назад

    Great explanation!

    • @CppNuts
      @CppNuts  2 года назад

      Glad it was helpful!

  • @MrTrutulescu
    @MrTrutulescu 4 года назад +1

    Join is linking one task after another!!!!

  • @ParvezKhanPK
    @ParvezKhanPK 5 лет назад +1

    simple , short and easy to understand... will be grt if u have added deadlock condition. mutex vs semaphore as well.. may be in next video..

    • @CppNuts
      @CppNuts  5 лет назад +1

      Yaa man, if i will include everything in one video then it becomes very big.

  • @isokemisoke
    @isokemisoke 2 года назад

    Hi I have a question, let's say we have a single serial communication port and we want to read two different things periodically in same period. In this case, there will be two request which want to use serialport.read function at the same time, so can we say our read function is a shared object ? Can we use mutex for these two periodic serial port readings ?

  • @praveerroshan8376
    @praveerroshan8376 3 года назад

    @8.12 -> what if ++myAmount throws exception ? then it will be locked forever. Instead we can use lock_guard ?

  • @soumyaranjansahu7018
    @soumyaranjansahu7018 4 года назад +1

    Awesome explanation sir....😊👍

    • @CppNuts
      @CppNuts  4 года назад +1

      Thanks man..

  • @omardumet120
    @omardumet120 2 года назад

    thank u so much for your videos

    • @CppNuts
      @CppNuts  2 года назад

      Glad you like them!

  • @rahulr9301
    @rahulr9301 4 года назад

    brother thanks a lot , i have one doubt when mutex is not used . Then either t1 or t2 will start . If t1 has started and makes x =1 and t2 also runs with some delay and makes x=2 , please clear me
    thanks

  • @vijayasajwan2830
    @vijayasajwan2830 4 года назад +1

    The vedio are very nice to understand the thread concepts.

    • @CppNuts
      @CppNuts  4 года назад

      Thanks man!!

  • @shantanu83
    @shantanu83 Год назад

    Very nice explanation.

  • @ThomCountryfan
    @ThomCountryfan 4 года назад

    Does this also work if I have only 1 thread but many users who start my program and try to run this same thread? For example: The thread should write into a file. Now many users can start the program at the same time and run the thread which wants to write into the same file. Are the threads also blocked from being able to access the file at the same time in this case?

  • @virtualclassesoncomputerpr5433

    I can understand the concepts explained by you,
    I want to know , in c++ , when we can pass arguments to a "child thread function" ,after execution of the "child thread function" , how to collect the return value (which is a vector) in the parent thread i.e., main()

    • @CppNuts
      @CppNuts  Год назад

      std::promise And std::future In C++ Threading
      ruclips.net/video/XDZkyQVsbDY/видео.html

  • @drallisimo34
    @drallisimo34 4 года назад

    cool tut!!!

    • @CppNuts
      @CppNuts  4 года назад

      Thanks man!!

  • @st-hs2ve
    @st-hs2ve Год назад

    mast samjhaya dhanyavad

  • @ARUNSINGH-td7eh
    @ARUNSINGH-td7eh 4 года назад

    Really great tutorial but I have a doubt, what will happen if same thread tries to lock() 2 times without using unlock() first after the first lock()??? I mean what will happen if same thread uses lock() 2 times and then uses unlock()?

  • @runescapefreedownload
    @runescapefreedownload 3 года назад

    Thank you!

    • @CppNuts
      @CppNuts  3 года назад

      You're welcome!

  • @phanialladi1810
    @phanialladi1810 3 года назад +3

    All the concepts have been explained clearly. Thanks a lot. If possible could you explain about threads creation using posix as well in a short video? @CppNuts

  • @waldrioliveira7537
    @waldrioliveira7537 2 года назад

    Super. Thanks

  • @ohm6454
    @ohm6454 2 года назад

    Hi I have some question
    What is the maximum critical section in one thread?
    and If I want two critical section in one thread how can I do it
    Thank you

  • @tinuscariathomas7691
    @tinuscariathomas7691 4 года назад

    std::mutex is similar to CRITICAL_SECTION in Windows and is used for synchronizing threads in the same process, right ?

  • @DhananjayPawar
    @DhananjayPawar Год назад

    output of the 1st code (Race Condition code ) is 2
    Its Vary Compile to Compiler or something else happen?

  • @jugalrajeshbhaishah1528
    @jugalrajeshbhaishah1528 2 года назад

    Pls help as u said 3:34 that there can be race and issue with final value of i but in my case i am facing problem am getting it same without mutex if i change i++ to ++i in thread func it does just u told else it dont.
    #include
    #include
    #include
    void ThreadWork(int& i);
    int main (){
    int i = 0;
    std::vector threadList;
    for (int j = 0; j < 10000; j++)
    {
    threadList.push_back(std::thread(ThreadWork, std::ref(i)));
    }
    std::cout

  • @nickpratap9161
    @nickpratap9161 5 месяцев назад

    Thanks

  • @bebel9349
    @bebel9349 3 года назад

    Great tutorial ! A bit slow but thats perfect to ensure understanding. Whats the name of the song used as intro ?

  • @praveenmourya9948
    @praveenmourya9948 2 года назад

    What happened if forget to add instruction m.unlock() ? in the critical section

  • @mohanrajawat6508
    @mohanrajawat6508 4 года назад +1

    very nicely explain mutux

    • @CppNuts
      @CppNuts  4 года назад

      Thanks for your comment dude!!

  • @tanugarg6822
    @tanugarg6822 3 года назад

    helpful!

  • @user-rr5ni6es1f
    @user-rr5ni6es1f 9 месяцев назад

    i compiled same program without using mutex it is working correcr then what is the use of mutex if i am getting same out put without mutex

  • @lujainbanbouk8493
    @lujainbanbouk8493 2 года назад

    best explanation :)

    • @CppNuts
      @CppNuts  2 года назад +1

      Glad you liked it

  • @devanakalyan4702
    @devanakalyan4702 3 года назад

    Good explanation

    • @CppNuts
      @CppNuts  3 года назад

      Thanks and welcome

  • @bsunil14
    @bsunil14 5 месяцев назад

    Sir, how it will work when T1 goes to CPU1 and T2 goes to CPU2, in case of multiple CPUs to change some variable or file
    ?
    Thank You, your videos are very very helpful 🙏

  • @rohitkumar-lj2ru
    @rohitkumar-lj2ru 3 года назад +1

    Instead of int myAmount = 0 ., we can go for std::atomic myAmount(0) will solve the race condition making myAmount atomic

    • @OlliS71
      @OlliS71 6 месяцев назад

      For this case this would be easier, but the task was to show how to use a mutex.

  • @s_e_t_z3248
    @s_e_t_z3248 Год назад

    Thank you

  • @matheusribeiro2739
    @matheusribeiro2739 Год назад

    brilliant

  • @vanukurinaga
    @vanukurinaga 3 месяца назад

    how can accumulator load two things at the same time

  • @mehulvora8225
    @mehulvora8225 Год назад

    What will happen if an error occurs while executing ++myAmount ? Will the mutex still be locked ?

  • @lukashk.1770
    @lukashk.1770 4 года назад +1

    perfect again

    • @CppNuts
      @CppNuts  4 года назад

      Thanks man!!

  • @mohammedumarsheriff5801
    @mohammedumarsheriff5801 3 года назад

    is there any method to find the minimum time taken by a processor or ram or a particular motherboard component to function?

    • @CppNuts
      @CppNuts  3 года назад

      There must be..

  • @mandeepkhadka388
    @mandeepkhadka388 4 года назад

    Samjhauta ;) nicely summed up :)

    • @CppNuts
      @CppNuts  4 года назад

      Glad you liked it

  • @UchihaNarutoFTW
    @UchihaNarutoFTW Месяц назад

    10:50 If there always will be a time difference between thread T1 and T2 when they are approaching a critical section, then how will there be a race condition? Then why would we even need a mutex?
    Sorry if this question is so simple. Noticed no one asked this in comments so I thought of asking.

  • @manikanta7981
    @manikanta7981 4 года назад

    Whether the other thread is in waiting state or blocked state? Once you said it is in blocking state and again you said it is in waiting state.

    • @CppNuts
      @CppNuts  4 года назад +1

      It is waiting for mutex.

  • @biswaranjan3550
    @biswaranjan3550 5 лет назад +2

    Hello Sir,
    Thanks for this video .I have one doubt if we are not using mutex lock and unlock in the given example then also it is giving the output 2 always and also we are not getting any run-time issues could you please clarify.
    Thanks in advance.

    • @ParvezKhanPK
      @ParvezKhanPK 5 лет назад +1

      try to create more than 2 threads.. may be 5 or 10 then you will see the difference.

    • @CppNuts
      @CppNuts  4 года назад

      As @Parvez said if you will create more threads the chances of being caught will increase.

  • @mdirshadalam2617
    @mdirshadalam2617 3 года назад

    Hi Rupesh, Can you please tell me how to run(not sleep) a thread for 10 minutes?
    sleep for 10 minutes or run 10 minutes a thread is equal?
    I am looking for the reply
    Thanks

    • @CppNuts
      @CppNuts  3 года назад

      Hi Irshad, i couldn't get the question. Please explain in details.

  • @ash_engineering
    @ash_engineering 5 лет назад +2

    It's a general purpose doubt : can we extend all this concepts of threading functionality in c Lang by using the stdio header file instead of iostream

    • @CppNuts
      @CppNuts  5 лет назад +2

      Yes there are so many things available in c programming language, look for pthread you will get everything.
      (unlike c++ , c programming doesn't have its own threading header you will have to use pthread)

  • @PARKATAMURGA
    @PARKATAMURGA 5 лет назад +1

    Thanks ! What happens if we don't use t1.join(), t2.join() here ?

    • @CppNuts
      @CppNuts  5 лет назад

      Please watch my join and detach video for full details.
      ruclips.net/video/q3-5sDe6lzg/видео.html

  • @kevin-ru6oe
    @kevin-ru6oe 4 года назад +5

    Actually I think that not only race condition is present when you modify the data but also when you access it and other thread/process modify it. For example, in a condition where something cannot happen when a count is zero. Suppose count is one, you pass the condition but in that moment, other process/thread start to execute and decrements count to zero, and then you return and make wrong this with that count.

    • @CppNuts
      @CppNuts  4 года назад +4

      Correct, that is called read write problem or write read problem, if you have studied DBMS there also we call it an issue. So it's not race condition when it is write write.
      So you are correct, race condition is there if wr or rw conditions are there, not only ww.

    • @kevin-ru6oe
      @kevin-ru6oe 4 года назад

      @@CppNuts Thanks for answer. Happy day

  • @swapnilkushwah8974
    @swapnilkushwah8974 4 года назад +1

    Can you please tell me which IDE/compiler you are using ??

    • @CppNuts
      @CppNuts  4 года назад

      Sublime text editor 3.

  • @vhxhao
    @vhxhao 3 года назад

    Question:
    Is data race condition always not recommended?
    If so, why didn't cpp std library just embed mutex inside the thread? if it was embedded, the threads can always guarantee it is race condition-free.
    is there any specific case we "want to" use race condition? or is it just lazy implementation?
    By the way, I love your videos!

    • @NeelSandellISAWESOME
      @NeelSandellISAWESOME 2 года назад +1

      sometimes we want to intentionally generate a race condition.
      consider global data
      int flag = 0
      consder thread 1
      while (flag == 0) {
      }
      consider thread 2
      if (flag == 0) {
      flag = 1
      }
      thread 1 is waiting for thread 2 to modify the value of flag so that it can break out of its loop.

  • @aashayjajoo8309
    @aashayjajoo8309 2 года назад +2

    Hi. This is a nice explaination of Mutex. Can you please upload a file for notes for all sections, that would be really helpful

    • @CppNuts
      @CppNuts  2 года назад +2

      Go to channels about page, u ill get the link.

  • @vaibhavgupta6u
    @vaibhavgupta6u 5 лет назад +2

    Hi ,Thanks for the video..Could you please explain how can we detect the race condition in our code ...I can't simply refer the logs as logs can be in GB ,please explain how can i debug the race condition..
    Waiting for your reply..Thanks in advance

    • @CppNuts
      @CppNuts  5 лет назад

      I heared that there are few tools or library which can find race conditions but never used it.

    • @vaibhavgupta6u
      @vaibhavgupta6u 5 лет назад

      @@CppNuts thanks, i was thinking ,can we debug and figure out the race condition without using new tool?if yes,then how?

  • @sajit1988
    @sajit1988 5 лет назад

    Hi Rupesh,
    What is the difference between critical section and mutex ?
    It is always recommended to use criticalsection to sync within same process and mutex to sync different processes...how criticalsection perform better over mutex?

    • @rajeshgalla12
      @rajeshgalla12 5 лет назад +1

      I think their is confusion; Mutex is used to Synchronies Critical Section. If you dont have CriticalSection then we dont need Mutex.
      @Rupesh, Thanks for the video. I believe adding one of realtime example on CriticalSection and mutex help a lot to audience.

    • @CppNuts
      @CppNuts  5 лет назад

      Sure man!

    • @sajit1988
      @sajit1988 5 лет назад

      Noo Rupesh,
      As per my understanding, there are 4 types of synchronisation methods.
      1. Critical section
      2. Mutex
      3. Event
      4. Semaphore
      I want to know why we prefer critical section over mutex to sync threads within same process...?

  • @antoinebouvier15
    @antoinebouvier15 4 года назад +1

    I don't understand... I have the same code than you but if i comment/uncomment the lock and unlock lines, the result remain the same... so I don't understand how is it usefull... Help?

    • @CppNuts
      @CppNuts  4 года назад +1

      So many people complain about this, i have tested in 2 different computers, actually 3 computer and i see everything is good.
      Really don't know how to debug this problem you are mentioning.

  • @amargandhi1137
    @amargandhi1137 4 года назад +1

    Can you please provide me the video on how to implement our own malloc function like mymalloc
    And
    What is smart pointer and it's types in CPP plz sir I humble request

    • @CppNuts
      @CppNuts  4 года назад

      Sorry i don't have such video for now.

  • @NAYAN0ashcatchup
    @NAYAN0ashcatchup 5 лет назад +1

    please make a video on v table..and v pointer

    • @CppNuts
      @CppNuts  5 лет назад +1

      Sure once this threading playlist will be over i will make video on virtual.
      Even i been waiting for virtual videos.

  • @sparshbhogavilli9566
    @sparshbhogavilli9566 Год назад

    10:10
    In a multi-core processor, is there always a tiny time difference b/w two threads?
    If that's the case, how can we call multi-threading TRUE parallel processing?

    • @CppNuts
      @CppNuts  Год назад

      What did i exactly mentioned in the video, if you can mention that may be i can answer to this question.

    • @sparshbhogavilli9566
      @sparshbhogavilli9566 Год назад

      @@CppNuts The timestamp I provided in the above comment is supposed to serve this purpose.

    • @UchihaNarutoFTW
      @UchihaNarutoFTW Месяц назад

      10:50 If there always will be a time difference between thread T1 and T2 when they are approaching a critical section, then how will there be a race condition? Then why would we even need a mutex?
      Sorry if this question is so simple. Noticed no one asked this in comments so I thought of asking.

  • @paraskaushik2639
    @paraskaushik2639 11 месяцев назад

    WOW

  • @ankitahlawat4812
    @ankitahlawat4812 5 лет назад +1

    please make video of recursive mutex

  • @JKA-sf7ll
    @JKA-sf7ll 2 года назад

    When multiple threads trying to access a resources,a threads get resources and lock it and once threads work is done it unblocks resources and make available for other threads.
    Prevents the race condition

  • @niteshsingh7674
    @niteshsingh7674 2 года назад

    @CppNuts : We might need some better example of race condition, as without mutex also the above program will might always(for me it always gave 2) give result as 2.

    • @CppNuts
      @CppNuts  2 года назад +1

      Computers are fast it is hrad to reproduce.