WEBVTT

0:00:00.000 --> 0:00:21.900
<v A>Programming Throwdown Episode 80: Concurrency. Take it away, Jason.

0:00:21.900 --> 0:02:10.940
<v B>Something new. We have a couple of people already, which is really great. It's pretty cool that we got to sort of work out some of the kinks and things like that. And we were trying out Discord, so we have a Discord channel. You know, this is something that I've mentioned off and on for years and years. Basically, we have Facebook, we have a Google+ page, we have Twitter, we have all these different media. We have email, which is where we probably get most of our traffic. You know, we've all these different things, and people can't really talk to each other. You know, because if someone posts on Facebook, you know they're only posting to one over n of the people, right? If someone emails us, you know they can't other people can't respond to that, right? And so with Discord, you know we're hoping that we can get something where, you know, people can ask. The one thing is, you'll be able to listen to the show live, which is pretty cool. So we're actually broadcasting live on Discord, but then also, like more importantly, people can ask questions. We set up a little questions channel, and you know we can answer them live or sometimes, you know, a lot of probably the majority of the questions, we actually just email back that person, and we don't really talk about it on the show. We also get a lot of the same question. You know, I think the most common question is is sort of like should I go to college or should I do a Nano degree and things like that? And we answer that directly to that person. And so this way it's like if someone asks questions by default that go there, you know can be seen by everyone. You can really help other people out with your question. Obviously, you know our email still works, so email is not a problem, but I figure we'll try this out and we'll see how it goes.

0:02:14.035 --> 0:02:14.997
<v A>New things are.

0:02:14.997 --> 0:02:29.579
<v B>Always. Yeah, and actually at Patrick's on this, which is that's one thing that separates this from every other platform, is Patrick himself is on this one. Well, I am right now anyways. You're pretty bearish on Discord.

0:02:31.922 --> 0:02:33.694
<v A>I am bearish on social. Yeah, anything.

0:02:34.302 --> 0:02:39.263
<v B>Yeah, I can understand that. Do you use Slack at work? Probably not, right? No. Yeah.

0:02:42.840 --> 0:02:48.038
<v A>Makes sense. Cool. Well, let's—I use Walk over to people's desks and I'm reminded why I went to the same office.

0:02:50.012 --> 0:04:07.160
<v B>That's a good point. I am somebody the other day who is like literally just a foot away, and I kind of realized, wait a minute, I should just talk to this person. So yeah, we'll just jump right into it. My first news article is 15 years of SparkFun. So SparkFun's an awesome website. They do a bunch of really cool projects. My guess is—I know they have a store too, right? So if you want to buy like a I don't know linear servo or something like that, or Arduino board, they sell them there. They sell some really cool kind of battery, you know, different form factors of batteries and things like that. But the thing they're most known for is just having really cool articles and having really cool how-to's and things like that. And they're celebrating 15 years, which is really neat. So not only is this article just a yay type article, but also they really go through and document the entire 15 years, and they're very candid about, you know, this is year one. I don't remember exactly who started it, but the person was who was writing this, and like this is year one, I'm by myself like in my basement starting SparkFun, you know. And they go through kind of the whole evolution of SparkFun, so it's pretty cool to read.

0:04:10.692 --> 0:04:21.205
<v A>Yeah, so hobbyist electronics components—that's how I would describe it. But yeah, specializing in having a really good documentation instead of obscure data sheets. Yep. Yeah.

0:04:21.390 --> 0:04:22.842
<v B>Totally makes sense. That's crazy.

0:04:24.220 --> 0:04:30.689
<v A>About 15 years? I don't even think—I don't even know when I was the first customer. It was early, but it wasn't 15 years ago. Yeah. Yeah.

0:04:30.689 --> 0:04:43.060
<v B>Wild. I had no idea that they had been around that long. I didn't get into robotics until very, very late. So yeah, for me it's the first thing I bought maybe a year ago or something, but yeah, it was really cool.

0:04:43.060 --> 0:04:51.074
<v A>Hmm, now I'm curious. I'm going to go search my email and figure out when the first time I bought something from them was.

0:04:52.778 --> 0:06:26.400
<v A>It's going to take a while. I'll do my new story instead. So my new story is building a CPU in the web browser. Uh, this is something I ran across. I think it was on Hacker News where someone was doing a show. Hacker News, and they were, I guess practicing their web skills. But I did play this for a while, and I found it pretty interesting. And so this is—we've talked about, I believe Nand to Net Tetris before, which is a similar idea starting with the lowest level gates and building up more complex digital logic gates, and all the way up until you have a processor. And Nand to Tetris even sort of programming the processor and going onward and upward. But this one, I think stopped short of that. I didn't do all of it from scratch. I did get, I think, to all the way through the adder. So starting with—I believe you start with a NOR gate, so using a NOR gate building up all the other gates, building up various logic components and then an adder. Nice. And they have a little playground canvas that you can drag components on to build them. And then once you sort of unlock a new component, then your next lesson uses that or is allowed to use that component. And so if you're interested in that kind of thing and want a super low barrier to entry, just you can head on over to nandgame.com, or we'll have a link in the show notes, and you can try that.

0:06:26.687 --> 0:06:56.843
<v B>Oh yeah, very cool. I played—I think it was Human Resource Manager something like that. Yeah, we made it sure. Yeah, I made it a tool to show one show, and that was very, very satisfying. And so yeah, I'll give this a shot. I think those games are just super, super fun because it's like it's the idea of you know, I built something, and then I am now able to sort of replicate that thing, and then you end up with like so many layers of indirection. So you have this really complex web. It's just really cool to watch. Yeah. So,

0:06:58.682 --> 0:07:25.277
<v A>This one's a little less polished from a UI standpoint than something like the Human Resource game, or so it's called like TIS-8000 or Shenzhen IO. There's a couple of others that are in similar veins. This one's a little less—you know, it's somebody mostly just sort of practicing. I don't want to be offensive, but from the way I understood the way it was posted, it was someone sort of learning to do a sort of web app, but they made something that was pretty cool.

0:07:25.277 --> 0:09:22.200
<v B>And doing cool. Nice. My next one is again about Discord why Discord is sticking with React Native. And yeah, this was super interesting. So basically for people who don't know React Native, it's a way where you write JavaScript in HTML—actually they call it I think JSX or something like that, but it looks a lot like HTML. And basically it will sort of transpile that into an app. Like it will basically, you know, distill that down into a native app. And so, you know, in this React Native system, you say, 'I have a button and I have, you know, some label,' etc., etc., and then you say, 'Okay, I want an iOS app,' and it goes and does all sorts of magic, and you end up with an iOS app that is native. So it's as opposed to something like Unity where you know you're manipulating basically individual pixels on the screen. And so if you make a button, you know, it's going to look exactly the same on everyone's phone, like pixel for pixel. But that's not really what people want. What people want is, you know, if they're on iOS, they want it to feel like an iOS app, and the same for Android, right? Also, you know, an incredible amount of work has gone into making those buttons and those text boxes and making sure the keyboard doesn't pop over the text box and all of that stuff, right? And you don't want to reinvent all of that. That would be very tough. So, so even if you did it wouldn't be like what people are used to, right? So React Native kind of gets around a lot of that. I mean, it's not a silver bullet, right? So for example, if the keyboard just interacts differently with text boxes on one platform and the other, then it could be on Android you're covering up a text box with a,

0:09:22.200 --> 0:09:43.669
<v B>keyboard, and it's really ugly. But on iOS you're not. And so you have to sort of finagle all of that so that you get something that looks nice on everything. And so this article is just all about a team doing that, and that whole experience. So they kind of document their whole journey with React Native. So I thought that was pretty.

0:09:45.863 --> 0:10:00.966
<v A>Cool. I feel like there's been a sequence of these kinds of things. I don't remember all the names because I don't do really mobile programming, but the React one seems to have stuck around for a while. I don't know if it's stuck around quote-unquote long, but it seems like it's been—yeah, there's a thing for longer than average. There's like

0:10:00.966 --> 0:10:15.951
<v B>there's like Xamarin was a big thing and there was PhoneGap where it was literally. Yeah, I remember that one. Yeah, and a lot of these kind of died out. It seems like React Native for whatever reason has just stuck. So I found

0:10:17.858 --> 0:10:19.630
<v A>My first spark fun order? Oh, nice.

0:10:19.630 --> 0:10:24.017
<v B>What time? What year do you want to guess? I'll take a shot. I'll take.

0:10:24.017 --> 0:10:25.570
<v A>A shot. How many years ago?

0:10:25.739 --> 0:10:42.300
<v B>Gonna guess that you needed it for some college project. And so when I'm told, 'Oh, we can't disclose how long ago,' I'm totally gonna age you out here, rat you out. But okay, let me just loosely guess. I'm gonna guess around like 12 years ago.

0:10:43.947 --> 0:10:46.191
<v A>Oh, that's a good guess. Oh, nice. Yeah, it was not for.

0:10:47.811 --> 0:10:52.739
<v A>A school? Oh, really? Oh, okay. I actually can see what I ordered and I know what.

0:10:52.739 --> 0:10:53.599
<v B>I did with.

0:10:54.966 --> 0:11:05.884
<v A>Them? Okay, all right. So it was actually well, anyways, I'm not gonna age myself. All right. I ended up building using Arduino to build like a little thing that moved around on stepper motors. Oh.

0:11:05.884 --> 0:12:09.604
<v B>Nice. Actually, speaking of that, you know my chest robot arm? I'm making good progress there. I'm posting on Facebook if anyone's is following me there. Like, but not as the podcast. You have to follow me because I don't want to—I want to keep the podcast pretty high like signal-to-noise. So, but yeah, the robot arm is pretty good. I have a little stepper motor. I'm actually looking at it right now, and it moves. I don't know, this probably isn't a good design, but you know, it works. Like basically, I have a platform that goes up and down or I guess left and right, and then that figures out which column to go the arm should pick from, and then the arm only has to think about one axis. Then—oh, that's nice. Yeah, so it seems to work pretty—I mean, it's not as fast I think as having an arm that could just needs to work. Yeah, I mean for me this is a huge accomplishment because I actually burnt a motherboard or melted—not a motherboard, I melted a breadboard because no one told me that you're not supposed to put seven amps through a breadboard. And wait, yeah, how did—

0:12:09.604 --> 0:12:13.654
<v A>You manage to even have something that could do seven amps?

0:12:13.900 --> 0:12:35.199
<v B>Well, I have the stepper. Maybe it's not seven, but I have the stepper motor and I have a digital servo, and the digital servo is for the shoulder of the robot. So, so I got one that's pretty powerful, and basically yeah, if I have the platform moving and I try to move the arm at the same time, it draws a lot—like I don't know if it's exactly seven amps, but it's a lot of amps.

0:12:36.975 --> 0:12:38.612
<v B>It's not seven. It's definitely you.

0:12:38.697 --> 0:12:43.455
<v A>Can't run seven amps through the PCB wiring? Oh, really? Oh, okay. That's not seven.

0:12:43.455 --> 0:12:52.045
<v B>It's okay. It's it's enough. Well, the breadboard can handle half an amp, and I melted the breadboard, so it's more than that. So you are somewhere.

0:12:52.045 --> 0:12:55.049
<v A>Over half an amp? That's my lower.

0:12:57.428 --> 0:13:01.200
<v A>And upper band? That—okay. Well, cool. Yeah, don't burn your house down.

0:13:01.200 --> 0:13:06.321
<v B>Though man, I'll try my best. You know, it's proving to be pretty difficult not to burn my house down, but

0:13:06.389 --> 0:13:16.024
<v A>Also yeah, you probably want to look at like motor drivers or adding a transistor so that it drives directly from the power supply instead of running through the Arduino if that's what

0:13:16.024 --> 0:13:17.965
<v B>it's doing? Yeah, I got so basically.

0:13:17.965 --> 0:13:19.635
<v A>Okay, you already do that?

0:13:19.635 --> 0:13:25.019
<v B>The breadboard is only there because I don't have a way to splice wires, so it's literally you don't.

0:13:25.052 --> 0:13:26.260
<v A>Have a soldering iron?

0:13:26.689 --> 0:13:27.449
<v B>I oh when's?

0:13:28.562 --> 0:13:29.406
<v A>Your birthday? I'll

0:13:29.406 --> 0:13:48.839
<v B>Send you one. I could. I actually have a soldering iron. I never even—oh no, actually it's—I don't have. Sorry, I have the split. What I don't have is the—I would need to take a regular wire and basically put the right adapter on it so I could plug it in.

0:13:48.840 --> 0:13:58.499
<v A>Or you could just cut off the adapter? I mean, yes. I run into this all the time. This is a horrible habit. I just end up cutting off whatever adapter and just soldering on whatever I

0:13:58.499 --> 0:14:00.355
<v B>Need? Oh man, that is so smart.

0:14:01.249 --> 0:14:11.594
<v A>So like oh, I have a power plug that has this barrel jack and I need to feed it into my Arduino like—asker it. I just snip off the barrel jack and then ta-da.

0:14:12.775 --> 0:14:21.145
<v B>Wires? Yeah, that's really smart. I should have thought about that. No, it's not smart. No, I mean it's resourceful or whatever. I never would have thought of that. Yeah, okay.

0:14:21.145 --> 0:14:26.241
<v A>Yeah, so just remember—I mean, you're hacking, so you can just cut off whatever you can't connect to. Yeah, one.

0:14:26.241 --> 0:14:26.899
<v B>Of the things.

0:14:26.899 --> 0:14:28.975
<v A>As long as if you don't need it back again. Yeah.

0:14:29.346 --> 0:14:40.600
<v B>Exactly. It's one of the things I'm having a hard time being destructive, but then it's like I bought this stuff to make this one thing, so I need to just get over that. Yeah, okay, soldering. Yeah.

0:14:41.344 --> 0:14:44.618
<v A>The next fun here. That's true. I want to know when you're making your own PCBs.

0:14:44.618 --> 0:14:46.997
<v B>Yeah, I'll call you and I get my fingers stuck together.

0:14:50.271 --> 0:14:52.364
<v A>Wait, what? Super glue? Solder? I don't know. Well,

0:14:52.364 --> 0:14:56.667
<v B>Solder is not that sticky, but solder is super hot, and I don't

0:14:58.000 --> 0:15:16.022
<v A>Know. All right, next topic. We're talking about Fortnite. Fortnite's popular. We talk about whatever's popular, like cryptocurrency was popular, so we talked about. Now I hear Fortnite's popular. Yeah, it's just SEO. SEO baby. Do you play? Have you seen? I have played it. It's—I ain't gonna lie, it seems too complicated. You?

0:15:16.022 --> 0:15:25.084
<v B>Know what? I feel the same way. And the only thing I like, I know granted I've only played a little bit, but I like the 50 verse. 50. Have you tried that?

0:15:26.333 --> 0:15:30.029
<v A>Uh, no. I like—I've played it literally three times, I think. Yeah.

0:15:30.029 --> 0:15:44.219
<v B>Me, it's not that much different for me, but they have this mode where it's just like PUBG and that it's 100 players, but it's literally two teams of 50. You know, it's pretty fun, I'm sure.

0:15:44.219 --> 0:15:47.005
<v A>Everyone's laughing because they've probably all played it before. Oh, sorry.

0:15:47.005 --> 0:15:57.096
<v B>No, no. I mean, basically the thing about 50 on 50 is you have very little control of the outcome of the game, but I thought it was pretty fun. Yeah, they made a billion dollars. Wow.

0:15:57.340 --> 0:16:11.220
<v A>So I played it on my iPad and I found the running and shooting was fine, and I've tried PUBG before. I played that a little more, but the building I found very difficult.

0:16:11.305 --> 0:16:32.348
<v B>Oh, okay, got it. So I noticed that—I don't know how people—and this is just because I haven't played enough. Some people have a way to build like entire towers. I don't know if they're like you know using some kind of macro, like you know at an input level, or if there's just a setting in Fortnite that I don't know about. Or just well, yeah. Well, apparently you

0:16:33.799 --> 0:17:28.187
<v A>And I are the only people who don't know because Fortnite has made a billion dollars since launching in October. True? So they are getting that money from somewhere. People are playing it. It's a thing. Even you know sort of non-traditional gamers have been playing that. I was listening to some podcasts—I think it might have been TWIT, which I listen to very rarely. I don't listen to a lot of podcasts, but I was listening to one for some reason, and they were speaking about that this is an interesting phenomenon where people are increasingly specializing into like specific games. So something like, 'I'm not a gamer; I play Fortnite, I play League of Legends, I play Dota.' Like, I don't play it. Used to be people would just play whatever game—whatever game was out, whatever game was new—but now there's increasingly people who just play Minecraft, just play Fortnite. You know? Like they were sort of observing that a lot of their friends and acquaintances only play a single game. Wow, it's really interesting.

0:17:28.474 --> 0:17:29.082
<v B>So I don't

0:17:29.082 --> 0:17:47.020
<v A>Know if that's—I don't know if that's true. I do experience that somewhat. Like I know some people at work who are sort of always playing the same game. Overwatch? Is that it? Oh yeah, yeah, Overwatch. That's one of them. Yeah, so a lot of these online multiplayer games they play very exclusively. That makes sense.

0:17:47.020 --> 0:17:58.460
<v B>I mean, at some points like chess or something, or playing you know poker with your friends or something where it's like you don't go to poker night and decide to play I don't know, like Rummy or something; they just always play Poker.

0:17:58.714 --> 0:17:59.862
<v A>Maybe. You don't let's

0:18:00.942 --> 0:18:03.675
<v B>roll the die to see what card game we're gonna

0:18:03.675 --> 0:18:04.740
<v A>play today? Settlers of Catan.

0:18:05.009 --> 0:18:13.480
<v B>Wait, yeah, that's just poker. Nice cool. Um, so now it's time for Book of the Show.

0:18:13.480 --> 0:18:14.939
<v A>Book of the Show.

0:18:14.940 --> 0:19:44.807
<v B>My Book of the Show is a podcast, but um you know I've been as opposed to listening to audiobooks, which is what I usually do. Um this month I just binged on this podcast, and uh I thought it was great. It's called Dear Harvard Business Review or Dear HBR. So I don't actually know too much about Harvard Business Review. Like I don't know exactly how it's affiliated with the university. Um but what it is is just people who study um the the the social part of businesses. So you remember in the last episode we talked about technical arguments, and um these people just focus on um just the the in and outs of working with in a company or even for yourself, or what have you? And um uh you know each episode focuses on a particular topic. Um so there's one episode: There's Bad Bosses; there's another episode that was Bad Reports, and they take calls—actually, they take I guess emails from the audience and answer their questions. They also bring on experts, you know, authors, people who are social scientists, you know, people have studied like industry, you know, and that sort of corporate culture and all of that. And uh it was really cool. I actually kind of—I totally binged on it. I watched um probably 12 episodes, and that was just super fascinating. So so check it out.

0:19:47.069 --> 0:20:14.423
<v A>Book of the Show is a science fiction recommendation. And we've had this author before, but that's John Scalzi's Old Man's War. And I decided to do something different because I always struggled to not give spoilers, so I'm just going to read—well, I would say the back of the book, but I'm just going to read the summary from Amazon. Okay? John Perry did two things on his 75th birthday: first, he visited his wife's grave; then he joined the army.

0:20:15.469 --> 0:20:17.477
<v B>Nice. That's a good lead-in. I know. Yeah.

0:20:18.389 --> 0:20:23.434
<v A>So if you're one of those people who enjoys the first one, two, three sentences, is that?

0:20:23.434 --> 0:20:25.206
<v B>The author who did Red Shirts.

0:20:26.033 --> 0:21:17.417
<v A>Red Shirts. Um also we've talked about Locked In, I think on this show that—that I recommended. And I also read from him Fuzzy Nation, which is actually him rewriting a much older book, but I don't know if I've mentioned it as a Book of the Show on this episode. Um anyway, so Old Man's War, about two-thirds of the way through, and so far I very much enjoyed it. And I believe it's turned into a series that has like a bunch of books, like seven or eight books, like a lot of books in the series, but this is the first one, and I'm—I've just started it, and so far I'm enjoying it. The three sentences said there's some interesting premises about what would it be like if old people and why would old people go to war? So okay. Um but yeah, you read—I did.

0:21:17.417 --> 0:21:20.084
<v B>I thought it was really interesting. Okay, it was really.

0:21:21.197 --> 0:21:24.522
<v A>Fun. The definitely not trademark infringing Star Trek story.

0:21:24.522 --> 0:21:41.093
<v B>Yeah, that's right. I mean, in general, I just love parodies, right? Because I love somebody basically you because you really have to distill something down to parody it. And so in general, I'm a big fan of parodies, and Red Shirts was.

0:21:44.552 --> 0:22:45.980
<v A>A great parody. Yep, cool. Um I listen to those on Audible because I have a commute, and so I spend a lot of time listening to audiobooks, get through a fair number of them. And I always listen to them on Audible. And if you would like to support the show and you would be interested in trying to listen to a free audiobook, you can go to audibletrial.com/programmingthrowdown, and you can get a free one-month membership which gives you a free book one credit for a book. Um and uh for me I'm always trying to like optimize picking a book, which Old Man's War is a great book so far. I think would be good to pick up if you're not used to listening to a lot of books, but I normally try to go for sort of bang for the buck. I look for books that are really long so I feel like I get a better value for my credit because basically all the books are kind of priced this way. Um But we have a whole litany of recommendations through the show notes of various books that both Jason and I have recommended that are available on Audible, so check it out. Yeah.

0:22:45.980 --> 0:24:19.379
<v B>The other thing I started listening to the podcast on Google Play, and at least on Android, the Google Play app has all sorts of issues. Like, I don't know if it was specific to that podcast, but basically what would happen is if you would pause it and then resume it, it would start over. I don't know why. Actually, now I think about it, someone emailed us saying that that happens to our podcast. I think it's just an issue with Google Play, but it turns out there's also podcasts on Audible, and so you can actually get Dear HBR and other podcasts on Audible. They don't cost any money as long as you have a subscription, and you know if you already have an Audible subscription, it's a much better user interface than the Google Play. Oh, I didn't know that. Yeah, cool. If you don't want to support us on Audible, you either already have an Audible account or you want to support us in another way. You could check out our Patreon. So that's patreon.com/programmingthrowdown, and you know I post the episodes there. So they give you any patron has a high-quality RSS feed. So if you are subscribed to us on Patreon, don't use the RSS feed on programmingthrowdown.com; you can, but the one from Patreon is super super high bandwidth. It's meant for patrons, meant to get you the episode like as fast as possible, and so check that out.

0:24:23.025 --> 0:24:25.641
<v A>All right, time for our tools of

0:24:25.641 --> 0:26:23.480
<v B>The show of the show. My tool, the show is PyTorch. So if you've ever heard of Torch, Torch was a library written in Lua and it basically gave you a lot of tensor type operations. For example, if you want to multiply matrices or add matrices to each other, you create like a neural network for doing some kind of AI project, you could use Torch. The thing about Torch was, you know, it was written in Lua, so it's hard to really make it play nice with other libraries. So for example, if you wanted to read some data from H5 and put that into your Torch model, you'd have to count on Lua having an H5 or HD5 reader, and that's—you know, Lua just doesn't have as much support as other languages. So they went ahead and basically ported all of Torch to Python, and so PyTorch is exactly what it sounds like. It's really sharp. I've been using it quite a lot lately, and you know in the past I've used other similar libraries. So I've used Keras, I've used TensorFlow, I've used Theano. I've used all pretty much all of these, and I think PyTorch is by far the best, and it's actually sort of taking over. You're just seeing more and more projects being done in PyTorch, and it's really a phenomenal library. You know, its design also—I mean basically you know all of these libraries or programming languages, really anything, they have the benefit of hindsight, right? So you know, in the case of PyTorch, they really just look at all these other libraries and said, 'You know what can we do differently?' And they've made some really good design decisions. So if you want to

0:26:23.480 --> 0:26:57.919
<v B>do some cool AI project or if you even need to do anything any type of sort of math-heavy project, check out PyTorch. It's really nice. I mean NumPy is good. The big difference between PyTorch and NumPy is that PyTorch can run on the GPU. There's a lot of differences, but that's sort of the big one. I was if somebody said, 'Hey, I want to do some math-like project that has a lot of heavy math in it, and I need to run really fast.' Then you could do it on PyTorch on the GPU. It'll just scream.

0:26:57.919 --> 0:28:31.520
<v A>Mine is also very educational and useful for work. Mine is a game nice called that's not probably funny because I think I do it every episode: Suzy Cube. This is—I did my homework this time. It is available on both iOS and Android. Nice. And this is a platformer in the style of, for me, it's most like Super Mario Land 3D, which is a Wii U game that I play with my kids that we like. It's very much in that style, and you're a cube character moving around in a 3D world, but most platformers or games of that type—I struggle with on tablets or phones, but the controls are done really well, and the game is a sort of good balance of feeling like you're making progress without just being like cruising through. This is super easy, no problem whatsoever. And I believe it's three or four dollars. I think probably—I think it was four dollars. But so it's not super expensive, and it was a good time. I've not beaten it yet. I've only—I'm only about four or five levels in, but I'm enjoying it. It has the you know common trope, I guess, of you can get through the level, which is a sort of feat of its own, but then there's also hidden stars, some of which are more hidden than others, and there's three stars on each level, and I'm trying to find those as an additional challenge.

0:28:31.520 --> 0:28:58.520
<v B>Nice. That's super fun. Yeah. I love games that do that because that way it's like it's like you have really two goals when you're playing on these puzzle games. The first goal—I mean assuming it has a good story—is to really experience that whole story, and the second goal is to solve obviously solve the puzzles. And so by having these sort of optional challenges, it lets you sort of pace yourself based on your skill, luck, and stuff like that.

0:29:02.054 --> 0:29:02.948
<v A>Yeah, so check

0:29:03.960 --> 0:29:12.600
<v B>it out. Cool. All right, onto the topic concurrency or as we kept saying before, the show cryptocurrency. Cryptocurrency con-crypto-currency.

0:29:15.149 --> 0:29:16.499
<v B>Yeah, con-crypto-currency. I think there's

0:29:16.499 --> 0:29:18.040
<v A>a crypto coin in there.

0:29:18.040 --> 0:29:24.379
<v B>Yeah, we should—we should start this. I mean, there's no way it could make less money than Dogecoin.

0:29:24.379 --> 0:29:29.580
<v A>I mean, Dogecoin's not the worst. Dude, we can name a lot worse than that.

0:29:30.302 --> 0:29:37.086
<v B>Oh yeah, that's true. That's true. Um, yeah, that's—I sorry, I guess what I meant to say is it's got one doge.

0:29:37.086 --> 0:29:38.706
<v A>Is one Doge? One Doge is?

0:29:39.752 --> 0:29:53.320
<v B>One Doge. Um, all right. So concurrency—so yeah, I mean how do you that died? Um, why would you do concurrency? Um, yeah, Patrick, why would we—why would we bother with concurrency?

0:29:53.320 --> 0:30:12.861
<v A>Why not? Concurrency is a way to, most people know that. Well, I guess there are a couple ways, but the main one is people know that there's more than one core in modern-day computers and even phones. Yeah, almost everything seems to have more than one core. I think even the newest Arduinos. Yeah, anyways, it's true.

0:30:12.861 --> 0:30:16.101
<v B>Maybe—maybe not Arduino. Yeah, probably even Arduino.

0:30:16.101 --> 0:30:59.960
<v A>Definitely the Arduinos, I think it does. Oh yeah, okay. Um and so if you want to leverage more than one of these, you need to do more than one thing at a time. You need to take concurrent work, and the normal programming we do—uh when you think about sort of writing C++ or Java, um JavaScript, I guess it will have to think about exact application, but if you're writing an application-level programming language like Go, um you know what—when you're doing that, you're writing a set of instructions you expect to execute sequentially. And the processor may do what's called reordering, but you you expect it to roughly execute in order, and there's a lot of things that have these dependencies: first do this, then do that.

0:30:59.960 --> 0:31:08.565
<v B>Yeah, basically it's a guarantee, right? So if you say like X plus two and X lines X times 10, and if those are swapped, you're kind of in big trouble. That's—

0:31:09.915 --> 0:31:18.201
<v A>True, but there are certain things you can run in parallel or swap and not get into trouble, like X equals two and A equals five, right? Right.

0:31:21.509 --> 0:31:22.369
<v B>Right. Yeah, but it's—

0:31:22.740 --> 0:31:49.049
<v A>Done behind the scenes. Yeah. Yeah, but we're telling that doesn't exist for now. And so concurrency is a way to be able to do, you know, like that example: X equals two and A equals five. If you want to run those at the same time, you would get done faster. However long it takes to do that assignment instead of having to take time to do it twice, you would get it in wall clock time—the time to execute it just once because they would happen on two different processors that are independent and can both take care of—

0:31:49.538 --> 0:32:13.754
<v B>It. Yeah. Um just to explain like so there's CPU time, which is basically like how many clocks does it take to do something, and then there's wall time, which is how much total time. So if you have a hundred things you need to do, the number of the amount of CPU time is probably fixed, let's say, right? But but if you could do 50 of them on one core and 50 on the other, you could half your wall time even though your CPU time hasn't.

0:32:15.306 --> 0:33:02.438
<v A>Changed. Yeah, and this is the—so when you talk about concurrency, you're talking about trying to get some amount of this, I guess you'd say parallelism. And there's a lot of things that talk about it, and formalisms, and even I was when I was studying up for this a little bit remembering from college these Petri nets and ways of describing parallel accesses. And then the—I guess the analogy I always hear is that you know there's different kinds of tasks which are more or less suited to concurrency. And the example is that if you have nine ladies, you can't have a baby in one month, but you could have nine babies in nine months, right? So if you have one—well, if they can only have one at a time, I guess this is an oversimplification and a slightly awkward example, but it's one that was always.

0:33:02.438 --> 0:33:03.980
<v B>taught to me Octomom proves you wrong.

0:33:04.244 --> 0:33:07.416
<v A>Yeah, okay. This is a bad example, but just take twins.

0:33:07.416 --> 0:33:09.340
<v B>Out of it or multiples out of.

0:33:09.390 --> 0:34:52.244
<v A>It. Yeah, and what you're trying to say there is that some tasks you really do, as Jason was saying, first I need to take X and add two, and then I need to multiply by 10. And if you do those differently, then you're going to have an issue. And so splitting that task, as simple as it sounds, onto two processors isn't going to go faster because one of them is just going to be stuck with nothing to do. So some tasks have these large sequential dependencies, and because of that, it just takes a while to do that. And adding more processors, you could duplicate that work. You could do more of it. But you—so if you had to do some image processing, one way to get parallelism is to take a whole image and do it on processor one and a whole image and do it on processor two. But depending on the task you're doing, it may be possible to do like the top half on processor one and the bottom half on processor two. And the two different scenarios are that if you're going to do both images all the way to the end, the total time taken—wall clock and CPU time is the same. But if you're only going to do one image in—in splitting the image in half, the first image comes out sooner wall clock time than if you have one processor doing Image A and one processor doing Image B. And that's an advantage often because often we worry about how long until we get the first answers out or the soonest answers out. Think about things like video games. And video games, you know, you need to get the whole frame rendered in a certain time. So doing a lot of the different tasks in parallel helps you get that frame out sooner versus a Pixar movie where you could spend a lot of time just working on a single frame and a whole different set of computers be working on a different frame than what you were.

0:34:53.509 --> 0:35:51.509
<v B>On. Yeah, yeah, exactly. Another reason why you want concurrency is if you have a lot of asynchronous calls that you have to make. So for example, let's say you have a web server and somebody, you know, goes and hits your web server. You want to hit a database, get some information from that database, and then send that information back to that person and wait for that person to get it, right? So you're doing a lot of waiting. You're waiting for the database, you're waiting for the person to get your reply, right? Sometimes you have to resend the reply if they didn't get it, things like that. And I mean, imagine if the web server just ran in one thread so like while it's doing all this waiting, nobody else could get on your website. It'll be terrible. I mean, most requests—I think—it depends on a lot of factors. Let's say they take a second. So that would mean you can only have one person per second on your website. You.

0:35:53.196 --> 0:36:59.599
<v B>know? So another thing to do there is use concurrency to say, okay, it doesn't even necessarily have to be—have to use multiple cores. It could just use one core, but it could just release, you know, some type of lock or something. So it could say, okay, I'm going to go to the database and ask it for some information, and until I get that information back, you know, I'm just going to chill, and someone else could do something on the core. And so that's how most web servers work. Is they—you know, just are this whole waterfall of asynchronous calls, and the entire time one of those calls is in progress, that well, I guess we'll call it thread to make it simple, that that thread is just waiting. So you could service, you know, 100 customers at the same time on one core even. And you're just taking advantage of the fact that you're spending a lot of time waiting. So yeah, that's the other sort of big use case between the two of those you've covered, you know, 90% of the uses for concurrency. Yeah.

0:37:00.274 --> 0:38:10.040
<v A>And I think it is useful because people talked a lot about having multiple processes or like if you ever did UI work or or still do not doing something on the main thread. And people sort of make this comment, but the idea is sort of what Jason is pointing out, which is even if you only have one processor, you do this time slicing. You could have prioritizations. But the idea is you want certain things to be very responsive. And if you need to do a long-running task—even if it's not going off to another computer—you want to make sure that that task that's long running has lower priority and gets interrupted to service things which you want a quick response to. So if you imagine like this is not exactly how web servers work, but you know, hey Jason, I have a question for you. And he says, okay, what's your question? I give him a complex differential equation he needs to go solve. You may want him to say, okay, I'm working on it and then go work on solving it, but getting a 'I'm working on it,' so I know he's not like dead or not responding to me, is a useful thing to have that like initial very quick response, right? And concurrency, even if you only have a single processor, allows you to sort of keep things working well.

0:38:10.040 --> 0:40:06.600
<v B>Yeah, exactly. And so basically the core mechanisms by which you get concurrency one is through message passing. So imagine you have sort of two threads and they're both running or let's say even two processes. So the difference between a thread and a process is multiple threads share the same memory, but multiple processes at least by default they don't share the same—the same memory. So you couldn't create an object in one process and just pass the pointer to another process and use the same object; it won't work. So for example, if you have two processes and you want them to as I said pass some object around, they have to one process has to serialize it, so turn it into just a series of ones and zeros like a string or something like that, and then send it to the other process, right? And you can do the same with threads as well, right? Just you don't have to, but you can. And we call that message passing, right? And it's—it's just the same as if you were to send a message to another machine on the internet or something like that. You basically are just going to package up that message, send it across, and other person's going to unpackage it. So if you hear things like IPC (Interprocess Communication), that's going to be a way to pass messages. And in fact, at least on Unix, you know, ICP—IPC and TCP work almost the same way. Like you can actually open a socket to another process on your machine or you can open a socket to, you know, yahoo.com or something like that, and it's almost the same code, right? So it's really kind of, you know, it's meant to work that way, right? Another way to do it is through shared memory. And so—you know, this gets a little bit.

0:40:06.600 --> 0:40:50.760
<v B>complicated because very OS specific. Like on some, especially older OSs, you actually have to use files and file locking and things like that. But at a high level, just imagine there's, you know, a chunk of memory that both processes can access, right? So actually, I mean if you're talking about threads, then everything is shared memory, right? So then it's just a matter of saying, okay, this object—I'm going to access this object from multiple threads and just sort of effectively writing some documentation and things like that so that people know that hey while they're, you know, editing this object or reading this object or something like that, it's possible another thread is also doing that at the.

0:40:50.760 --> 0:42:23.460
<v A>same time. Yeah. So I mean, I think for these threads, especially in the last few years, this has gotten in—I guess application programs much easier. So in Python there's threading, in Java there's now there's always been threading, but there's easy ways to even just sort of multi-process streams where this shared memory kind of happens without even thinking about it. And even in C++ there's standard thread now and standard async, which standard async is still a little broken, but oh wait, really tell me more? Well, no, I forget the exact nuances. And I think like I do a lot of my work in C++11 and 14, and it was broken then. I don't know if they fixed it in 17. Async has a weird dispatch policy. Is the long and short of it, you have to take special care to make sure you're like when you run a standard async command, it happens, right? Then like the function will run in parallel when you think it does as opposed to sort of getting deferred, if I recall the argument correctly. But yeah, so I mean, as Jason pointed out, the first sort of threads—it's just implicit what you might even like I was mentioning, you might just sort of write an anonymous function, a lambda function, or have a function call just in line with something you say, hey, I want to go do this 10 times, or I want to go do this across these slices of the data. And that's just an object that you're sharing out to those threads. You don't—it doesn't have to be copied; it just gets accessed in place.

0:42:23.460 --> 0:43:58.440
<v B>Yep, that totally makes sense. One last thing about this is there are like thread pools and process pools. And so the idea there is you're creating a thread—is actually especially creating a process is pretty expensive. I mean, you know, the computers nowadays are so fast that you really don't notice, right? I mean, unless you're doing a lot of it, but under the hood there's actually pretty significant overhead around creating those things. And so there's this concept of a pool where basically you know at the start of your application you say, okay, I know I have a ton of work to do and I know I have let's say eight cores, so I'm going to create eight threads right at the beginning. And these eight threads are just going to start taking work. So as soon as I—have some work, I'm going to say, hey, eight threads, you know, go and take this work. And I don't really, you know, and there's a lot of complexity around okay which thread is free, who can accept the work, etc., etc. So the thread pool kind of abstracts all of that away. So you basically—and almost every language has this. You basically say, 'Um, you know, I want a thread pool with eight threads,' and then you can just say `pool.you know it depends on the language` `pool.nq` or `pool.start` or something like that, and you could give it a function, and it will, you know, handle—you know if you call it nine times in a row really quickly, it'll take that ninth one and it'll wait for the first for one of the first eight to finish. You know, it'll it'll kind of handle all of that for you.

0:44:01.035 --> 0:45:59.802
<v A>So the thing to point out is if you use message passing—whether you're talking to something on the same computer or two different computers, as Jason was pointing out with this sort of socket example—is actually not immediately obvious to you or really doesn't make much of a difference as far as you writing the program is concerned. But if you're doing shared memory, there's extra steps that need to be taken. Or even if they're—even if you're using processes sometimes you need to use a resource like I need to talk to oh, that's a bad example like the hard drive, let's say, and I'm going to be writing stuff out in the heart. Oh, the speaker. I need—I want to go talk to the speaker, and if two programs are talking to the speaker, it would just be nonsense. So in our system, we don't want, you know, the speaker to be accessed by multiple programs. So there's this concept of, you know, locking that resource so that I'm the only one who writes to it so that garbage audio doesn't come out. And so in order to do that, these locking concepts need to be done typically by the operating system and exposed in the programming language in some way. But they allow you to sort of do coordination, and the things you would hear are semaphores, mutexes, locks, and they come in a variety of forms, but roughly they're all around this making sure that you don't collide in how you're trying to change or use something. And what that amounts to is mutexes are mutually exclusive, which says there's some bit of code and I want to guarantee that when I run this bit of code, I'm the only person with regards to some, you know, some signal, and that is if there's two threads running the exact same function—it's probably the same block of code—you only want to be executed one at a time. But it could be two different things. You want mutexes in order to protect.

0:46:00.240 --> 0:47:17.005
<v A>I said the speaker. And so you want to say, 'Hey, I have a mutex.' Anytime someone's gonna use the speaker, then they're gonna acquire the mutex. And you know that when you acquire the mutex, that you're the only one who will be talking through the speaker at that time because everybody else is mutually excluded. And then you get into a conversation about instead of just doing this with a variable where you could end up with a race condition, but even if you avoid it, the nice thing about mutexes is they often have the built-in concept that instead of polling—where the processor is busy in a very tight loop just going, 'Are you free? Are you free? Are you free? Are you free?'—there's normally more sophisticated mechanisms where you'll be able to put the other threads into a state where the processor is free to do other work, put them effectively to sleep and have them get woken up when the mutex is free for them to acquire. And that has the advantage of allowing again the computer to process more stuff. So as Jason's example, when something goes off to use the database, you don't want to just saying sit there saying, 'Is the database transaction done? Is it done? Is it done?' You want to sort of be notified, okay, hey, I'm done now, and receive that signal so you're not locking up all the computer processor just asking, 'Are you done?'

0:47:17.933 --> 0:48:33.020
<v B>Yep. Yeah. And so the mutex implementation, you know, even on every language, it comes with a lock object. And so what the lock object does is you say, 'Hey, you know, lock this mutex.' And what that will do is it will lock it, and any point from that lock call onwards, you have total ownership. No one else is in that code. Or if someone else has the lock, it'll just wait. So you know a common problem is a common problem with multi-threading is that you could end up saying, 'Okay, I want to lock this object because I want to increment it.' And you have another object you want to lock and you want to let's say print that you incremented it. And if you have different threads sort of locking different objects, you can end up like causing the system to be really, really slow and not realize it, like you because it's not—you're tracing through your code and you're saying, 'Oh, this function's pretty quick. This function's quick.' It's very hard to know how long a lock will take because you kind of have to think about what else is going on in the system.

0:48:33.020 --> 0:50:32.300
<v A>Yeah, that's right. And this is sort of these shared memory versus message passing. And there's a variety of other things are I guess a formal way of describing, but what I often find in practice is that you see somewhat of a kind of hybrid solution. So what I've seen kind of the most for when someone actually has to go handle raw concurrency themselves is in a language like C++ or Java, you end up spinning up some threads to do something and you have a queue that describes sort of each of the things you want done, and you put a lock on that queue. And so you effectively get a kind of low-cost lightweight message passing interface where I have a job queue of things I want to go execute. It might be like parameters or little messages that have come in or pieces of an image, and I sort of add a description of the work to be done to a queue. And then I have however many threads that spin up, and when a thread wakes up, it reads it tries to acquire the lock on the queue. It reads the data out of the queue and then releases a lock, does its work, and then there's typically an output queue where when it finishes, it acquires the lock on the output queue, puts the data in, unlocks it, and goes back and tries to get something from the input again. And if you just sort of do that over and over again, you end up with an effectively what looks a lot like message passing but using—and that the sort of inputs and outputs are going into a shared structure, but the individual things themselves aren't aren't shared. The individual sort of parcels are, but you might have a read-only something that's shared, like you might only pass the pixel coordinates of the image to process, but the image itself is kept read-only. So even though it is shared, you're not really editing it and you don't run into maybe the same complexity you might if everybody was simultaneously editing the image.

0:50:33.632 --> 0:50:45.630
<v B>So yeah, the two big pitfalls are one is race conditions. Do you want to talk about race conditions? I'll take deadlocks.

0:50:45.630 --> 0:52:09.347
<v A>Okay, sure. So race conditions is a generic term, but it just means when two things are running in the system, you can get unintended consequences where you think you're—you know, I want to set variable A to two and then B to three, and then something happens where you find out during debug that A was three when B was three instead of A being two. And it might be because some other piece of code was setting A to three and then B to something else, and you have this race condition where two people are modifying something and you think it should happen in a certain order, but because they're sort of not synchronized in some way via one of the locking mechanisms or semaphores we discussed before that you're sort of up to a chance where sometimes it might happen in a way that looks sort of a little bit out of order. So an example would be like A printing to the screen. If you have two threads printing to the screen, the data can get intermixed, and that is sort of a race condition that you're trying to write out your whole message, but while you're trying to write out, someone else comes in and writes out too. And that might not be a harmful race condition, but sometimes race conditions can be harmful where you sort of think almost transactionally like this set of operations going to happen all at once, but in reality somebody else could come in in the middle and do something, and that would result in a race condition.

0:52:10.360 --> 0:52:31.082
<v B>Yeah, exactly. I mean a simple way to observe this right is if you create two threads and those threads just immediately try to print 'Hello' and then print 'World.' You'll often get 'Hello Hello World World,' right? And so as soon as you start introducing kind of in that case, as Patrick says, just printing, so you start introducing logic that becomes really yeah.

0:52:31.082 --> 0:52:40.060
<v A>So you think about 'Hello world' coming out as sort of one unit of thing, but in reality it's actually many, many different instructions that have to run.

0:52:42.338 --> 0:52:43.401
<v B>Yep. Yeah, exactly.

0:52:44.059 --> 0:52:45.122
<v A>So what are?

0:52:46.118 --> 0:52:50.202
<v B>Deadlocks. All right. Deadlocks. I'm gonna see if I can get this.

0:52:50.202 --> 0:52:51.029
<v A>Right. Hang on.

0:52:51.029 --> 0:54:50.720
<v B>I hear, I hear Wikipedia. What is? No, no, no. You tell me. Check me out, okay? But I think so. So for example, let's say I'm trying to come with a really solid example. Let's say for example you have a thread that is—let's say you have some type of database and this database is holding information to email. So it's some kind of reporting database, right? And then you have a reporting service. You have a you have a thread for just kind of managing that database. Then you have a reporting service, and this service, you know, takes things from the database and actually sends them out over email, right? And so you have these two threads, and so you have a sort of mutex. So when the database is updating—the sending the service has to wait, and when the service is, you know, pulling something from the database to send it off, the database has to wait to update, right? And so now someone goes in and introduces let's say multi-part messages or like some kind of instant message or something like that. So the database is updating, and while the database is updating, the database gets this request that says, 'Okay, send an instant message. I need this to go out immediately.' So it you know waits on the server. It says, 'Hey, you know service that's sending out these emails, I need this to go out right away.' But the service that's sending the email, they are in this loop where they are waiting for the database to finish updating. So because remember how they work, right? They wait for an update and then they check it. So they're waiting for the database to update. The database update has this new like emergency mode and it wants to send something, and they're

0:54:50.720 --> 0:55:24.980
<v B>both waiting on each other and that's a deadlock, right? And it's actually extremely easy to do that, and it's very painful because what happens is your system just grinds to a halt. And you know, you can usually see this happening because all of your logs will just lock up, everything will just lock up, but you won't be using any of the processor. It just kind of sitting there as if it's idle, and so that's—that's a pretty painful situation. We actually had one of those a couple of days ago, and it's not pretty to debug. It's really difficult.

0:55:24.980 --> 0:57:21.130
<v A>Actually, yeah, I think it's—yeah, difficult to explain, but I mean, extracting out the most obvious dangerous conditions is when there's more than a single resource that you need to get your job done. So if a single process needs to use things that are locked by more than a single protection mechanism, so that's, you know, when would you have—oh, that's a good way of two systems and I need to lock system A and do something, but then I also need to go lock system B. And maybe at the start you don't say, 'I just want to lock A and B together,' because maybe what I'm doing with A takes a really long time, and then B I only need for a very short amount of time. But then if you have another process which needs B for a long time and then A for a short time at the end, what before finishing off A, you know, a right to B? Then what you can end up is, as Jason was trying to describe, is you end up with this—this deadlock where, you know, A gets locked, B gets locked by two different processes, and then they go try to lock the other resource but it's held by someone else, and you're sort of stuck. And this happens. It sounds really like, 'Oh, I'll just never do that,' but as Jason is saying, it's actually pretty subtle that you're doing this because in a really big system there's often many locks flying around and being locked and unlocked, and people are trying to write code efficient. And for me, the thing that—that I sort of when we deal with them at work as often as possible, and we'll get to this in a second with advice, is try to just use a single lock until you know you don't—that's not working for you, and you actually prove that that's inefficient. So if you have multiple things that need protection against race conditions or need mutexing, try to just lock them all together even if that's less efficient. And so what that means is, say I need to, you know, have resource A, and then there's—

0:57:21.990 --> 0:57:49.547
<v A>also a resource B, but I'm not using it, but someone else might want to use B and share it. And so you say, 'I'll create a lock for A and a lock for B,' but then now you have this opportunity where if someone else comes along and needs both A and B, they can end up in this race condition state. So instead just say lock A and B at the same time, like all of the resources which are prone to having this condition all sit under a single lock because if there's only one lock in the system, you actually never can have

0:57:51.252 --> 0:58:13.679
<v A>this problem. But that's an oversimplification. It doesn't always work, but it works more often than you think. And a lot of times if the—if you can do the work needed in the lock very, very quickly, then the amount of contention, the amount of time spent, as Jason was saying, waiting around for the lock to be freed, if it's low enough, then it kind of doesn't matter that there aren't these fine-grain locks. Yeah, exactly.

0:58:15.400 --> 0:58:53.014
<v B>I mean very rarely do you need a lock for a long period of time, especially like if you follow that sort of design pattern that Patrick mentioned earlier. You know, you're only accessing the lock to just like send basically signals around, and all of the work is happening outside of the lock. And if you—if you kind of can follow that, then you never need so many locks. You never need that much control. Yeah. But yeah, basically, you know, both Patrick and I have done a lot of threading, and it's a total—it's a total nightmare. It's very hard to debug. So

0:58:53.588 --> 1:00:40.920
<v A>I'll transition into my first bit of advice, which I just gave one, but I'll give another, which is a lot of times people think, 'Oh, I'll multi-thread this. I guess this is early optimization problem again, but like I'm going to multi-thread this or I'm going to add concurrency here,' and where they're really just getting is complexity. There's a lot of overhead, and not just these locks, but also as Jason mentioned spinning up threads, allocating deallocating things. You tend to end up with more copying of the data because as you're trying to organize it and stuff. And so non-obviously sometimes you—for instance, if you can only split it into sort of two or three threads, the startup and organization cost for having three threads do the work may not be enough to merit having the multi-threading. It might be faster just to have the single processor work on it and be done with it rather than going through that overhead of trying to split it up into parts and parceling it out to everyone because there's inherently more synchronizing and organization that has to happen as part of that. So one my big catch-in-out advice is both have measurements in advance that show you need an improvement, and then when you go add or start adding it, add it in as simple a way as you can, and show that you're actually getting a speed up because it might be that the overhead dominates the cost and the actual computation. Like we mentioned, you know, setting a variable or doing a simple addition. If you're trying to multi-thread just doing an addition, that's not going to be ideal because addition runs really fast. And so unless you have a ton of additions to do—you know, say I only have five, but I'll put them in, you know, five different threads and have it do it, the overhead cost is going to dominate there because the amount of work to be done is really small.

1:00:43.124 --> 1:01:15.422
<v B>Yep. Yeah, exactly. I mean, the biggest piece of advice that we could give is—don't do concurrency unless you absolutely have to. And even then, really try not to do it yourself. Like for example, let's say you need something that reads a thousand files, and you know, let's say you know does some transmutation of those files and creates a thousand new files that are slightly different, right?

1:01:17.582 --> 1:03:11.060
<v B>You know, you could—you know, it makes sense. Like you could use a thread pool and you could have all your cores reading these files and all of that, but something way, way easier is just write a program that reads one file and creates a one output file, and then use GNU Parallel. So if you're on Unix, you could type the word 'parallel.' That's actually your program, and so it's—it's all it takes a little bit of time to learn how it works, especially if you know you need to read a bunch of files and then you create output files that are the input file name dot data or something like that. You know, it's a little bit of exercise in learning how that works, but it lets you write programs that are just very small and simple, and they'll run—you know, GNU Parallel will run as fast as your computer can run, and they have all sorts of different tricks to speed that all up. There's just Bash doing all the parallelism for you on OS 10. You have to use Homebrew, and 'brew install parallel.' I don't think it's on by default, but you could just do that, and now you have it there too. So yeah, GNU Parallel and writing something that just does one file is will eliminate most of the parallelism. You know, also there's a lot of async libraries, like for example we've mentioned Node.js on the podcast. If you're using let's say Express, which is a web server library, Node.js—they do all the parallelism for you. So basically, you just create handlers. So you say, 'Look, when someone comes to my website and they enter this URL like /me, then I want to go and fetch their account and print it.' And you know, that handler can get called, you know, 10 times from 10 different threads, and you

1:03:11.060 --> 1:05:05.680
<v B>don't even have to manage those threads or anything. It's all done for you. So so almost every web server library does that part for you because they know how difficult it is. So yeah, the last thing I would mention is basic linear algebra systems, so BLAS systems like PyTorch and NumPy, and these SciPy and these other—these other systems. Under the hood, they're doing multi-threaded. So basically, you know, if you say 'NumPy dot add A and B,' A and B are our matrices. Under the hood, it's going to use all the cores of your computer. It's going to have a thread pool. It's going to spin up all these threads. It's going to even do like SIMD and all of this stuff, but you don't have to have to do with any of that yourself. You just say 'add.' So even—you know, PyTorch has the multiprocessing module, or we talked about Julia in a past episode. You know, a lot of these libraries will even do multi-processing or even multi-machine. PyTorch has torch.distributed for multi-machine, and you don't have to really mess with any of that threaded code. It's all abstracted away, and that will work for 99% of these cases. All right? So yeah, I think the other piece of advice is—definitely do a lot of logging. Make sure my last piece of advice is is make sure that when you log, you log the thread so you can actually usually get the pointer to the thread object or something like that. That way you can kind of tell your threads apart. And yeah, definitely start small. Write lots of tests—unit tests and things like that if you have threaded code because you're

1:05:05.680 --> 1:05:12.060
<v B>you're amplifying the amount of errors, and also the effect, the penalty of having an error is amplified. Man, we

1:05:14.929 --> 1:05:18.580
<v A>had all this interesting conversation, and then we just basically said, 'And try not to do.'

1:05:18.580 --> 1:05:46.266
<v B>any of this. That's great. Yeah, exactly. I mean, people have to do it for you. You know, I've done—I mean like the eternal terminal thing that I wrote is full of full of threads. So, you know, in your career, like it'll be very hard to get out of it. So our advice is, you know, don't do it if you can help it, but both Patrick and I do multi-threaded code regularly, so—you know, you won't be able to get away with it all.

1:05:48.443 --> 1:05:51.120
<v A>time well i look forward to probably not seeing any of you on the discord

1:05:55.699 --> 1:06:10.920
<v B>well you know we just announced it uh like uh an hour ago so oh because you're patrick i thought okay yeah patrick is gonna go into recluse mode now you had your opportunity you had two hours four five there's like four there's three

1:06:10.920 --> 1:06:13.800
<v A>three people who uh dropped by so there we go

1:06:15.375 --> 1:06:15.949
<v A>or four

1:06:15.949 --> 1:06:24.977
<v B>people that's right so you three people got a rare exclusive chance to uh see patrick actually engage in a in some type of multi-user forum but mostly you

1:06:24.977 --> 1:06:29.922
<v A>could have just you could actually just be streaming this to them and pretending like i was live that's

1:06:30.479 --> 1:06:32.120
<v B>true all right catch you later

1:06:44.603 --> 1:07:07.089
<v B>the intro music is axo by binar pilot programming throwdown is distributed under a creative commons attribution share alike 2.0 license you're free to share copy distribute transmit the work to remix adapt the work but you must provide attribution uh to patrick and i and uh share alike in kind of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a narrative of a

