Multithreading Code - Computerphile

Поділитися
Вставка
  • Опубліковано 13 гру 2018
  • We take multithreaded code for granted, but what's needed to make it work properly? We need two Dr Steve Bagleys to illustrate this!
    / computerphile
    / computer_phile
    This video was filmed and edited by Sean Riley.
    Computer Science at the University of Nottingham: bit.ly/nottscomputer
    Computerphile is a sister project to Brady Haran's Numberphile. More at www.bradyharan.com

КОМЕНТАРІ • 558

  • @davecool42
    @davecool42 5 років тому +1556

    And the visual effects Oscar goes to...

    • @TheRandomSpectator
      @TheRandomSpectator 5 років тому +32

      You could even see the reflection of both of them in that monitor behind them!

    • @brod515
      @brod515 5 років тому +13

      @@TheRandomSpectator I mean that comes for free

    • @STRAIGHTBOXMUSIC
      @STRAIGHTBOXMUSIC 5 років тому +3

      @@TheRandomSpectator u noticed too

    • @dipi71
      @dipi71 5 років тому +4

      Best Computerphile video ever, I'd say. Congrats!
      But was it also the most difficult Computerphile video to produce?

    • @taylorfaucett8282
      @taylorfaucett8282 5 років тому +1

      Who? You forgot to finish your sentence.

  • @Nayus
    @Nayus 5 років тому +618

    When he handed the token to the clone I was really impressed. This was great

    • @OpenGL4ever
      @OpenGL4ever 4 роки тому +4

      The force is strong with this one.

    • @yato3335
      @yato3335 2 роки тому +2

      Oh wow I didn't even notice that 🤣
      It was so seamless, I forgot it was the same person

  • @BillBodkin
    @BillBodkin 5 років тому +866

    this is next level editing

  • @VredesbyrdNoir
    @VredesbyrdNoir 5 років тому +508

    I get the impression the University of Nottingham once ordered 5000050000 boxes of that old style continuous feed printer paper back in the 80's and still don't know what to do with it all.

    • @kemfic
      @kemfic 5 років тому +78

      VredesbyrdNoir they feed it to the grad students

    • @pewp43
      @pewp43 5 років тому +53

      I wouldn't recommend using their washrooms.

    • @kemfic
      @kemfic 5 років тому +23

      @@pewp43 new channel: physicsphile - where physicists solve problems with single-ply toilet paper

    • @derpmarine216
      @derpmarine216 5 років тому +6

      you literally get it in giant crates for cheap.

    • @MrLampbus
      @MrLampbus 5 років тому +2

      Although they did get an Acorn A5000 out of the deal (lowest machine in the stack on the desk behind). I had (have in store still) one - great ARM machine but a bit light on RAM.

  • @gracejenna9787
    @gracejenna9787 2 роки тому +8

    My husband works from home. He is a very intelligent programmer, he talks to me everyday. This stuff is one of them. I am just drinking coffee while listening to him. I had no idea what he is talking about every single day. Thanks for helpful video. I will watch this everyday.

  • @bilalzahory7765
    @bilalzahory7765 5 років тому +70

    Just a reminder that the point of the video wasn’t to optimize the code for finding the sum of all the numbers that add up to 1,000,000, but to break down how multi-threading works and some solutions you would use for more common scenarios. Great video!

    • @nullvoid3545
      @nullvoid3545 2 роки тому +2

      thanks for this.
      My first thought was making "a" into 2 variables and then adding the results would be faster at the expense of some memory.
      Am i right is assuming this?

    • @bernardoborges8598
      @bernardoborges8598 2 роки тому +8

      There is a close formula for adding numbers in order so this is really just for demonstration purposes. Sum(1 to N) = N*(N+1)/2

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

      Wouldn't that be optimized away by the compiler with optimization flags on anyways?
      You should just write your code to be readable, then only optimize if you're sure there's a bottleneck(by profiling)

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

      @@Lightbringer7734 no one cares. This isn't a video about compilers. Sounds like you're scared of having to think for yourself

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

      @@nickwilson3499 wut?

  • @merlingallagher4484
    @merlingallagher4484 5 років тому +148

    What still amazes me. This is "just" an educational tech related channel, were a professor/teacher is explaining stuff about computers and IT stuff.
    Yet, it has 1.2 MILLION subscribes and around 20k views in a few hours.
    Great job guys, you show that learning (tech) stuff is just really enjoyable!
    On a way that apparently a lot of people can understand! thumbs up!

  • @menachemsalomon
    @menachemsalomon 5 років тому +16

    A good Part 2 would be explaining how the mutex works, because implementing the mutex also runs into the read-modify-write problem.
    Kudos for the visual effect of two Steves, especially handing the disk back and forth. Steve gets credit for his acting skills, and bonus points for having a 3 1/2" floppy disk just lying around on the desk.

  • @slpk
    @slpk 5 років тому +108

    The floppy disk transition was pretty clever

    • @simontay4851
      @simontay4851 5 років тому

      Yes, i want to know how that was done. Steve 1 seamlessly passed it to steve 2 as if he was real.

    • @ais4185
      @ais4185 5 років тому +3

      @@simontay4851 Are you trying to say he isn't real?

    • @snooks5607
      @snooks5607 4 роки тому

      never done any video CGI but if I'd have to guess someone was sitting there accepting the disk initially, then they switched places and had real time split-screen of the previous footage running on a screen so they can verify the disk aligns on the second pass.

    • @carlosmspk
      @carlosmspk 4 роки тому

      @@snooks5607 Still how did he deliver the disk at the precise level each time. You'd expect some altitude difference that would make the floppy disk "snap" from one altitude to another (and there is, but very, very little, which is impressive).

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

      @@carlosmspk Any imperfections in position are masked by the outline

  • @B20C0
    @B20C0 3 роки тому +7

    The first time I felt smart watching a Computerphile video. I saw the code and the fact that both threads use the same variable and thought "That's not gonna work as intended.".

  • @UweEichel
    @UweEichel 5 років тому +222

    That was some great editing! Good job and great video!

    • @lawrencedoliveiro9104
      @lawrencedoliveiro9104 5 років тому +6

      Not just editing, but also choreography of Steve’s movements.

  • @MirkWoot
    @MirkWoot 5 років тому +20

    I want 8x Steve solving all my tech problems and projects.

  • @nazoj6462
    @nazoj6462 3 роки тому +7

    Steve literally divided himself like a cell just for this example
    thats some true dedication

    • @gravity6316
      @gravity6316 5 місяців тому

      steve just forked himself

  • @aylazer23
    @aylazer23 4 місяці тому +2

    Wow, finally after a while I understood how threads and mutexes work. The visuals are great

  • @maxtaylor3531
    @maxtaylor3531 5 років тому +87

    Bagley is exactly like this in lectures. The only difference is he has awesome, black, heavily animated keynotes.

    • @recreant359
      @recreant359 5 років тому +20

      Max Taylor I woulda stayed in college if these guys were my professors.

    • @MatthewTaylor86
      @MatthewTaylor86 5 років тому +2

      That sounds amazing

    • @maxtaylor3531
      @maxtaylor3531 5 років тому +12

      He’s honestly a legend. Gutted I haven’t got any modules with him next semester.

  • @Peds013
    @Peds013 5 років тому +401

    Insta-liked for multiple Steves :-)

  • @kemfic
    @kemfic 5 років тому +217

    The numberphile and computerphile people have seemingly endless amounts of feed printer paper and butcher paper for some reason

    • @gmc9753
      @gmc9753 3 роки тому +6

      Maybe back in the 1980's, some company offered the university a great deal for a huge number of boxes of green bar paper.

  • @Gnarrrl
    @Gnarrrl 5 років тому +3

    Having the multiple Steves talking over each other and interfering with each others task to explain what happens in multithreaded tasks was quite brilliant!

  • @jangambler9998
    @jangambler9998 5 років тому +7

    Not sure if this is an actual educational video or just the editor and Steve flexing on their editing and acting skills respectively.

    • @oysteinsoreide4323
      @oysteinsoreide4323 4 роки тому +2

      i found the content clear. but I already have been dealing with locks, and programs not always giving the same result. And of course the video production itself can be educational at the same time. Win win situation.

  • @snooks5607
    @snooks5607 4 роки тому +12

    3:00 for completeness, there's also a thing called "green threads" where OS is cut out of the resource management and it's all done by the user-space application. reasons for this vary but for one it might avoid context switching in compute intensive cases.

  • @nem64
    @nem64 5 років тому +9

    I've always had love for parallelism and multi threading. This video explained it even more. Thank you!

  • @toxicdesire8811
    @toxicdesire8811 5 років тому +22

    10:57 I need a 10 hour version of this.

  • @TheChondriac
    @TheChondriac 5 років тому +6

    This is one of the best videos posted to this channel in a while. Really really great upload! I like that we actually got to see some code. I'm finishing my second year toward my degree in computer science and this is right at the level that's great for me. Cheers!

  • @poke_champ
    @poke_champ 5 років тому +1

    Needed this month's ago for my exams but was a great reminder! Your videos always help me and other programmers understand the concepts visually and practically!

  • @TheSiddh123
    @TheSiddh123 5 років тому +1

    The method of explaining how a thread works and how we can use mutex for the solution was exemplary. Great editing.

  • @sethnuzum
    @sethnuzum 5 років тому +2

    One of the highest value channels on the platform, thanks so much for the fantastic content!!

  • @ShujathHussain0
    @ShujathHussain0 5 років тому +1

    explanation and visual presentation are just outta the world.
    teaching every CS student wishes for

  • @vovakarma7885
    @vovakarma7885 5 років тому +1

    Great to see Steve programming ! Very educational how he organizes the code and writer it!

  • @billykotsos4642
    @billykotsos4642 5 років тому +114

    Merry Christmas Computerphile!!!!

  • @PhilipBlignaut
    @PhilipBlignaut 5 років тому +1

    One of the best multithread examples ever!
    Well done!!

  • @Wolves2314
    @Wolves2314 5 років тому +1

    This was a great video. The visualizations were awesome and I love seeing actual code.

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

    The best explanation of threads that I've even seen -- great job! Oh, and of course brilliant video production.

  • @RodrigoVzq
    @RodrigoVzq 5 років тому +4

    This video was just brilliant. Great production

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

    One of my favorite vids by yall guys. Thank you !

  • @emkaix93
    @emkaix93 5 років тому

    i really enjoy dr. bagleys explanations. keep up the good work

  • @MihaiStoian1
    @MihaiStoian1 5 років тому +4

    This is so educational, please do more videos with multithreading subject! ❤️❤️❤️

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

    Oh, what a great video. I wish I was introduced to it when I was learning about multithreading because it makes it look so easy despite the fact that all the things in this video I learned in a very hard way.

  • @ko.pi.pe.
    @ko.pi.pe. 5 років тому +96

    The `time` process is not well equipped at all for measuring performance at the microsecond level, as you found. Many things skew the results, as a whole process needs to be spawned and torn down, and this stuff is included in the total; context switching also will bite you. I only use `time` for benchmarking when the benchmarked process is expected to run for longer than one half second.
    Also, remember that there's a Bash built-in also named `time`, which is even worse than /usr/bin/time.
    `gprof` or `prof stat` would have been a much better choice.

    • @sugarbooty
      @sugarbooty 5 років тому +10

      Would making the set of numbers being added together larger to make it last longer increase the accuracy of the time process?

    • @snooks5607
      @snooks5607 4 роки тому +6

      ​@@sugarbooty sure, you could also measure the difference with a physical stopwatch but why make things hard for yourself. right tool for the right job.

    •  3 роки тому

      Do we not have access to a low level high res timer?

  • @pmiron
    @pmiron 4 роки тому

    Everyone learning programming should look at your video. Great explanations as usual.

  • @philippetrov4881
    @philippetrov4881 5 років тому +29

    My vision for education in programming is that the students should learn multithreading right from the start - in the introduction course. That way we can form a "divide and conquer" approach to solving problems from the beginning and not struggle to fight their "linearity" in thinking afterwards.
    The problem is that most of the people tend to use the methods of programming they know best, they know best whatever they used most and they used most whatever they learned first. So when we introduce parallel programming say in third or fourth course in the Bachelors degree it's already too late.
    Nowadays the mainstream programming is over multicore computers and parallel thinking in problem solving is a must.

    • @mrrdelorenzi8478
      @mrrdelorenzi8478 5 років тому +1

      scratch has multi-threading (it is taught at primary schools).

    • @theblackwidower
      @theblackwidower 5 років тому +7

      I spent three years studying programming in college, we never once covered multi-threading. Really annoying.

    • @justgame5508
      @justgame5508 5 років тому

      T Duke Perry I stumbled upon multithreading myself during my final college assignment (not university), It was a cloud storage app programmed in windows forms(C#) I had to use multithreading for the networking aspect, ie keeping the user interface responsive while downloading/uploading files and on the server allowing multiple clients to access data simultaneously. It was never formally taught however

    • @philippetrov4881
      @philippetrov4881 5 років тому

      @@theblackwidower that's very sad to hear...

    • @philippetrov4881
      @philippetrov4881 5 років тому

      @@justgame5508 what I do in my courses is that we start directly from GUI programming (Java Swing in NetBeans). That way we directly hit the responsive interface issue in the second lecture. We usually make some simple game - like a bad guy chasing a hero around the board so the hero must be in one thread controlled by the human and the bad guy in another. We then follow the path down towards low level programming.

  • @jesseokeya
    @jesseokeya 5 років тому +1

    Getting more in-depth knowledge on parallelism and multi threading. Thanks!

  • @Guitarm4n99
    @Guitarm4n99 5 років тому +1

    Awesome special effects, and really good topic!

  • @AbdulFourteia
    @AbdulFourteia 5 років тому +2

    Hats off to the editor and the presenter, and one more time to the editor.

  • @eotsdev
    @eotsdev 5 років тому +2

    love the two Steves!

  • @OzHarrrry
    @OzHarrrry 5 років тому +1

    The production quality is Insaneeeeee

  • @hrnekbezucha
    @hrnekbezucha 5 років тому +1

    Great job! I can see somebody had a bit of fun with this one

  • @bobplested55
    @bobplested55 5 років тому +4

    Please do a video on how you had two Steves, apparently motionless wrt each other, while using a hand held camera, and interacting with each other. That was too cool for School.

  • @simontay4851
    @simontay4851 5 років тому +11

    How the hell was there a second identical steve in the video at the same time and how did steve 1 on the right seamlessly pass a real floppy disk to steve 2 on the left as if he was there. That is some very clever filming and editing by Sean Riley.
    Sean, if you read this, please reply.

    • @Computerphile
      @Computerphile  5 років тому +17

      Hah, it took five times longer to edit than any other, may have to do a behind the scenes on how.... Sean

    • @bsharpmajorscale
      @bsharpmajorscale 4 роки тому

      It must be the work of an enemy stand

  • @NeilRoy
    @NeilRoy 5 років тому +2

    Very nicely done! We can never have enough Dr Steve Bagleys. ;)

  • @Bowhdiddley
    @Bowhdiddley 5 років тому +1

    The presentation and editing in this video is the best I've found on UA-cam when it comes to explaining and demonstrating multithreaded execution. Amazing job Dr. Bagleys and Computerphile.
    I'm a computer engineering student and one of the concerns I had when learning about and experimenting with multithreaded programming was the _real_ performance gain. As was shown in the video, the summation example didn't benefit a ton from being multithreaded. I assumed that a lock like a mutex creates a major bottleneck in your code that really makes it no faster than the single-threaded, sequential case. Moving the lock to the end of the function to minimize its usage made a lot of sense and, at scale, I could definitely see how multithreading would be the way to go!

  • @xSCOOTERx2
    @xSCOOTERx2 5 років тому +1

    Steve and other Steve complement each other very well.

  • @MrSonny6155
    @MrSonny6155 5 років тому

    This summarizes the difficulties in group work. All parties are working on the same thing, slowing down efficiency due to mutex locking.
    Of course, that assumes that there is even a mutex, because most of the time it's just a single guy doing all the work, with the other parties blackmailing that thread to credit them equally.

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

    wowww the editing was superb! nice job computerphile nice job

  • @kisame_5331
    @kisame_5331 5 років тому +1

    Best 15 minutes I've ever spent today

  • @andrez76
    @andrez76 5 років тому +2

    Great video as usual, though this one gets a prize for cool editing effects. I was wondering; how about using two separate accumulators, one for each thread, and adding them together after the join?

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

    Very helpful. I'm proficient in shell scripting and powershell overall for my work life, and recently started learning C. This helped me sort out a problem with one of my projects, so thank you for that. =)

  • @nitishgupta6802
    @nitishgupta6802 4 роки тому

    Find me a better channel on UA-cam, I'll wait .
    Every time I come to computerphile, it blows my mind open.

  • @BassHelal
    @BassHelal 5 років тому +52

    Learned more in 15 minutes than I did in my entire university Concurrency module.
    Awesome stuff as always :)

    • @RoccoBruehl
      @RoccoBruehl 5 років тому +3

      nice profile pic ^^

    • @TheUglyGnome
      @TheUglyGnome 5 років тому

      You went to Patriot University?

    • @BassHelal
      @BassHelal 5 років тому +6

      @Zero Cool Of course I was exaggerating, the course was bad and the lecturer didn't care, so I had to take things into my own hands but yes they did somewhat go over this stuff in that course just extremely poorly

    • @Toopa88
      @Toopa88 5 років тому +1

      @Zero Cool my professor in databases was from Russia and couldn't speak English neither the language that's spoken in my country. I don't know how he hasn't been fired yet but I assure you that you learned more in 1 hour research than the entire course.

    • @vitfirringur
      @vitfirringur 5 років тому

      This is your problem. You're in a university. You're not supposed to be spoonfed by the professor. You're supposed to learn to study on your own. If you expect everything to be spoonfed to you, you'll have a hard time finishing your education.

  • @dasten123
    @dasten123 5 років тому +1

    Interesting topic, well explained, nice editing. Thumbs up!

  • @nickbarton3191
    @nickbarton3191 5 років тому +6

    When I was first at work 40 years ago, we used to call operations that interrupts or the threads can't interfer with Atomic operations. These days nobody has a clue what I'm talking about.

    • @X_Baron
      @X_Baron 5 років тому +5

      Atomic operations are used in real-time computation, when you can't afford mutexes slowing things down or making response times unpredictable, and to prevent priority inversions. There is std::atomic now, and std::memory_order. Of the PC applications that people use daily, games are the most performance-critical and hence require these kind of features.

  • @gggfx4144
    @gggfx4144 5 років тому

    Really interesting video; explained concept of multi threading well and liked the example in code - thanks very much

  • @53nat0r
    @53nat0r Рік тому

    Superbs explanation. Well done! Great editing too!

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

    Loved the video! Absolutely great!

  • @rpsloss
    @rpsloss 5 років тому +1

    This was really well made. Thanks!

  • @MatheusOliveira-xw7vf
    @MatheusOliveira-xw7vf 3 роки тому

    Thank you so much, this is channel is helping me tremendously.

  • @neeraj4258
    @neeraj4258 5 років тому

    Visual effects were superb

  • @T-She-Go
    @T-She-Go 3 роки тому

    I understand so much now 😌 Those visual effects helped a lot 🙌🏾

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

    Visuals were sick!

  • @jayyyzeee6409
    @jayyyzeee6409 4 роки тому +1

    Gauss' shortcut:
    The sum of positive integers from 1 to x, where x is even is equal to: (1+x) + (2+[x-1]) + (3+[x-2]) + ... (x/2+[x/2+1]) = (1+x) + (1+x) + (1+x)..., where there are x/2 terms, or (1+x)*(x/2). The example in the famous story about Gauss was finding the sum from 1 to 100 which is equal to (101)*50 = 5050.
    In this case, x=1,000,000, x/2 = 500,000 => The sum is (1+1,000,000)*(500,000) = 500,000,500,000.

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

    Please make more videos on threads 🙏 this was great ✨✨

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

    Love the explanation, thanks other Steve!

  • @__jan
    @__jan 5 років тому +1

    holy moly that editing

  • @Teck_1015
    @Teck_1015 5 років тому +1

    Some damn fine editing here :)

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

    Great Video!! he explained following things
    - Race Condition Problem
    - solved race condtion problem using mutex.
    - code inside lock and unlock is called critical section.
    i have read so much about this but never seen program which explain all these concepts!!
    AMAZING VIDEO!!!!!

  • @skepticmoderate5790
    @skepticmoderate5790 5 років тому

    Very impressive! Merry Christmas.

  • @artit91
    @artit91 4 роки тому +1

    It was the optimiser. It sees you are adding a fixed amount of numbers to a variable so it converts to a + sum(stuff) form and puts the mutex around it auto-magically.

  • @RobertBlow
    @RobertBlow 5 років тому +1

    Thanks, I learnt something today. Brilliant.

  • @gamersforever1585
    @gamersforever1585 5 років тому

    very informative thank you for your brilliant work

  • @Huizelogica
    @Huizelogica 5 років тому

    i love his enthusiasm

  • @misterguru5135
    @misterguru5135 5 років тому +1

    Steve Ception!! I like it, that was awesome! :)

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

    Amazingly explained !

  • @Cybeonix
    @Cybeonix 5 років тому +70

    Steve-P-U Huh? Sounds like a RISC-y piece of hardware ;)

  • @mattimhiyasmith
    @mattimhiyasmith 5 років тому

    Love Steve's teaching

  • @danielnavarrete8571
    @danielnavarrete8571 4 місяці тому

    What a great explanation!

  • @woosukbyun2455
    @woosukbyun2455 8 місяців тому

    is there a way to see threads stored in the code section of physical memory?

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

    Learned a lot for this! Thanks!

  • @DiddlySquids
    @DiddlySquids 5 років тому +1

    I did a project rendering 2D fractals using multithreading. This video would have be SO helpful. I'm gonna share it with everyone who hasn't done the project yet.

  • @ben6
    @ben6 4 роки тому

    Incredible video!

  • @allmight9991
    @allmight9991 8 місяців тому

    This is really helpful thank you Hussein.
    Fan from egypt😊

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

    What magic is this with the floppy disc :D:D Amazing!

  • @timjohansson4304
    @timjohansson4304 5 років тому

    Hmm did you change the main function to what it was before? Otherwise it would still have been a single thread program! Awsome editing with the multiple Steves. :)

  • @robertboran6234
    @robertboran6234 5 років тому +1

    Nice explanation. We master the sequential process a long time ago. We have very good mathematical models on sequential processing but even now in 2019 we lack a good mathematical model on concurrency processing. Having a huge complex program and trying to split it in multiple threads is a nightmare. I think because we have only two hands our minds are not good at concurrency thinking. I would really like to see a programming language where the source code file has "normal code - handled by programmers" and on top of it there is a "synthetic code - handled by AI", the "synthetic code" is invisible to the programmer and it is in the same source code file. So the human job is to write the code and the AI job is to split the same code automatically. So as a human we don't need to know that the code was run in a complex concurrent fashion. This programming language can have multiple layers (Human layer + many AI layers). It is quite difficult to make a sequential looking code (TEXT) act concurrently (This just makes the code look quite complicated) .

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

      the two hands thing doesn't even hold up. We actually can't do more than a single thing consciously. Everything else consists of routines we learned and that only need our attention when they're being stopped, started, modified etc. Take walking down the street while talking on a phone. We can walk without consciously thinking about it, we are decent at observing our surroundings without it and we can produce speech without it. We only need to think about where we want to go and the content of our speech, all the muscular functions are completely automatic. Once you think "a quick brown fox" you don't need to actively think about how to produce that sound.
      And when learning to play an instrument, for example, you can quickly see how we are completely unable to coordinate both hands as long as we have to actively think about their movement.

  • @abdalhadifitouri131
    @abdalhadifitouri131 5 років тому

    I like this guys videos because they're a little more advanced.

  • @heaslyben
    @heaslyben 5 років тому

    I loved second Steve!

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

    Just blew my mind

  • @shivamsood8385
    @shivamsood8385 10 місяців тому

    really awesome explanation !!

  • @deckluck372
    @deckluck372 5 років тому

    The shared memory location coherency is like a read modify write instruction used extensively in symmetric multiple processors for example semaphores.

  • @TheSulross
    @TheSulross 4 роки тому +2

    Even though C++ (since C++11) has added threading to its standard library, in a lot of situations am still preferring to design around forking where a parent process supervises child processes to do the real work. With copy-on-write optimization of forking, the cost is the page mapping of the process address space having to change upon context switching per kernel scheduling. But the forked child process has a private heap that doesn't have contention with other threads for access. In the age of big data processing, this tends to be more crucial - plus it's a more fault tolerant design approach for implementing self-healing software services that need to run robustly 24/7 (child processes are vastly easier to scavenge successfully than a failing thread of execution which can tend to destabilize the entire program). I prefer this so much to multi-threading that I wrote a custom Java launcher called Spartan that enables (easily) breaking my Java programs into child processes - just as with C and C++, I can write a single Java program that splits itself into a parent and (one or more) child processes for logic execution. And the Java heap gets problematic (perf-wise) when dealing with more than 4 to 6 GB of memory objects - is really better to run concurrent, heavy data-centric processing in multiple child processes instead of one Java process using threading in a single heap that starts going well beyond 6 GB of memory utilization. Oh, and here's another optimization of this approach - the Java child process just does a System.exit() when its done so that there's no attempt to garbage collect multi GB of objects - in fact with Spartan, its feasible to launch the Java child process such that garbage collection is turned off - just allocate memory until done but never bother to reclaim it - the OS does that when the process exits. In Golang, it's a different story - pretty much have to go with model that's baked into the language. It's light weight compared to other language threading models, and garbage collection these days now works much, much better.

  • @JasonL220
    @JasonL220 5 років тому

    Very well explained!
    (I know this is sideware ... but) DON'T use mutex's in production code without thinking about if it is the best solution, they scale very badly (as the number of threads increase, and the amount of code the lock is held over) and if you are not careful can deadlock your process (i.e. every thread is waiting for another thread to relinquish the lcok). In this example C11/C++11 atomics should be used instead of the lock to add the final results, then there is no overhead from the context switch of the mutex system call, and deadlock is never an issue.

    • @mrrdelorenzi8478
      @mrrdelorenzi8478 5 років тому

      Yes, a mutex is a way to use threads, to create single threaded code.

  • @ardiansyah6794
    @ardiansyah6794 8 днів тому

    You can build university with this content quality