Get my Fundamentals of Networking for Effective Backends udemy course Head to network.husseinnasser.com for a discount coupon (link redirects to udemy with coupon applied)
Man you should start a podcast for this stuff, just put some of it on spotify for us to listen to it in the background. You are so good at explaining these things in such a casual way that you are kinda having a conversation rather then just explaining, thats a real skill. Would love some of this on spotify to listen to while just cleaning up and stuff.
Not only was your explanation informative and served as a great recap of the differences between these paradigms, but you were funny too! Your engaging personality kept me interested for the whole video, and it was over before I realised :)
This is what they always told me at work, understand the basics, understand the basic.. and here I am always ended up getting confused in basic. And back to ur channel to relearn all those things
You probably dont care at all but does anyone know of a trick to get back into an Instagram account..? I was dumb forgot the password. I would appreciate any assistance you can give me!
@@ahmedmalakai9753 If u still did not get back to ur account, it is as simple as clicking forget the password and that will send an email to ur gmail and then create new one for that instagram account !
@@ahmedmalakai9753 wait ok why are you asking here? This seems like the world's #1 most irrelevant place to ask that question. no shade or anything but like, i mean where did u think it was gonna go?
I clicked the thumb up button after I watched the whole video, and I ended up given all video I've been watched a thumb up in this channel, thank you Hussein!
I loved this explanation! You might consider doing a podcast when you just chill by yourself or with a guest and start off from some technical subject but treat it casually and with lots of everyday examples, just like you did in this clip. New sub from me and keep it up! :D
Thanks to the geniuses who made coding so easier for us newbies in the 21st century. Imagine, having to code back in the 70's or 80's, with no software like VS Code that can color code your text, auto complete lines of code, spin up the compiler/interpreter with just a click of a button, handles the communication with the OS, does syntax error check, etc. All we have to do is just know how to and what to code.
Great video, as usual. To summarize: if your app is "i/o bound" (e.g. reading data from a db, and sending it back) then use the asynchronous model (like NodeJS). If you are doing something "cpu bound" (e.g. video processing or cracking passwords) then use something supports subprocesses and channels (like golang).
Hussein the way you express yourself echoing in my mind. I like your passion and professional attitude which are seen rarely together man. True engineer
multithreading languages tend to solve the problem by introducing reactive programming, Java did this after the community introduced some technologies like RxJava. and it is very power to combine both in the language echo system. however hard to perceive from the first glance. Great video buddy, all my wishes to you.. keep up bro
Also, one of the reasons a lot of people moved to asynchronous programming is performance. Multi threading model, aka 1thread/request or thread pool model, induces a lot of context switching between threads, since everytime a thread blocks it’ll be removed and put back when the blocking operation completes. This operation has a hefty cost at scale, while with asynchronous programming you have a fixed set of threads (generally the number of threads your cpu supports) doing non blocking operations.
I love your explanations and as someone who is trying to become a backend engineer, I think your channel is a gold mine of useful information. Keep up with awesome videos!
I agree, multithreading is hard to code but it's worth doing especially if you combine it with asynchronous execution you will have the most responsive, memory-efficient application I'll go with multiprocessing only when execute a rarely use case with heavy logic
This was a good watch. I think I see single-threaded async behavior differently now. I am now also very interested in process interop now. Most of all, I have a weird urge to try working with multiple asynchronous single-threads at the same time.....
I guess proxies interest you more than anything (They come up at least once in every video of yours) !!!..Btw, I am a fan, and Thank you for the great content
Like to see u have very less subscriber, but still u r no bother about it.. u just share very unique knowledge on this channel. Which i have never find on other channel. Thank You, keep continue. sharing is caring.
As usual fantastic video Hussein but in multi-processing we have to go with IPCs and the like and we will lose the shared memory space (which exists in multi-threading) among the threads. That is one key need in problems that involve high real-time update-rate. I see what you are saying about the locks and all the headache that comes with them and you nailed it there.
Well said Thanks Osama, good points, one slight addition; you can have shared memory between different processes (postgres is an example) of course you have the same trouble of managing the shared memory
@@hnasr you got it right Mr. I usually go with Redis for more or less and have all my global "shared" variables there. If you are aware of faster alternatives, I am all in. Thx again.
@@hnasr what do you think of green-threads used in Go and all the collaborative scheduling that comes with them. I am planning on taking a deep dive there once we deliver the current project.
I think you can mix asynchronous and multiprocessing. I did something like that with fastapi using asynchronous functions and a Procfile with different microservices running on different ports
Regarding the multiprocessing use case for password cracking, if that's done on a particular machine, that's pretty much another variant of bitcoin mining ASIC but with different hashing algorithm. And the machine is optimised for this parallel workload.
@@hnasr Even Khan Academy style drawings are good or even basic white board. I feel when things are explained with visuals and the key points are written down then it's easier to absorb the information
Love all your videos, specially about soft skills and motivation one. There are times when I get lost and watching these videos again put me on track and keep going.
This is great man, I like your style of teaching! I kind of revise this topic once in a while and I'm going to bookmark this video so I revisit it later on.
In a real-life scenario, imagine working as a receptionist in a coffee shop. When working synchronously, you handle one customer at a time, and the line of waiting customers remains inactive until the previous customer receives their order. Multithreading involves teamwork, where a friend assists in taking orders by opening a second counter. However, the challenge arises as you may end up interrupting each other's work. If done effectively, productivity doubles, but without coordination, the service quality may suffer. On the other hand, asynchronous work involves taking orders continuously and serving customers as orders are ready. This method ensures smooth service flow as you can efficiently notify customers when their orders are ready while continuously serving the next customer in line.
I love your videos too much! 🥰 They are so deep and teach advanced concepts instead of just showing how to write a "hello world!" In a hell language 😐 Need more ^^
Have this doubt, how would you solve a sudoku using any of the techniques in the least time. Most favourable would be to use multithreading in this case. How to implement it? It is kinda a complicated problem.
Java handles multithreading perfectly well, synchronized keywords ensure no 2 thread has access to a method executing a code whilst still in the execution state until the current thread releases the lock. It also avoids deadlocks due to its synchronized nature. I don't know how to implement this in NodeJS.
In your explanation of asynchronous non-blocking flow while waiting for an I/O response, the single-threaded flow does not wait and continues to go on. If the one and only thread did not block and it continues to go on, how is the I/O response got detected? Does it spawn another thread to detect the I/O response? Or does is the one and only thread doing context switching back and forth?
A good example is nodejs, it is a single thread that does an event loop. The thread sends to IO request and moves on to do something else, then it comes back to check if it got a response (polling) the OS. It gets complicated depending on the type of async io the OS supports. Recent linux io_uring is a game changer. This video might clarify ruclips.net/video/gMtchRodC2I/видео.html
I did it.... Syntactical sugar😂😂... I love your explanation man.... We are the new generation where we don't write multithreading or async code, we IMPORT libraries to do it for us😂✌️
this dude is hot and he makes sense. ok. his channel also has a bunch of solid videos. im rollin with him. will watch every single video in the coming weeks. good stuff.
Salam, i think mixing both is good. I like both multi threaded + asynchronous.. i dont like big event loops or when language doesn't really support await thingy you have to invent your own or bring some library which im not fan of doing so
I have to disagree about staying away from multithreading. They have their own use context, with their pros & cons of course. And so it is that they came up with worker threads in nodejs. But I liked your explanation. Really funny the js event loop part. Regards!!!!
Fantastic explanation. I sense some nginx prior tinkering which got you into this stuff. If you take a deep dive on the read modes async io, direct-io your audience will get much more value. Bravo and keep them coming.
Good defs, BUT... ;) ... I agree w/the multi-threading bad rap... yes, you have to put some legwork in to get it working right because of easy resource access conflicts. Its not as hard as it sounds though once you understand it. BUT... once you do, this is the most performant way to write code. Mutli-processing is essentially multi-threading at a process level. So you do get the benefits of parallel execution and the speed. BUT, problem is, inter-process communication is SLOOOW. In olden days this was called Out-Proc, vs. In-Proc, was in-process communication. Essentially any communication within the same process boundary is the fastest there is. Any communication across process boundary is MUCH slower, by a factor of 100 or so. So there is a definite downside to multiprocessing vs. multi-threading, IF you want the processes to communicate a lot. If not, then its not an issue. Async/Await, is basically a cheap/simulated multithreading. Its maximizing the use of the single thread, which is awesome, but it will never be as efficient or powerful as multi-threading for obvious reasons. BUT, its the least people should do. Not doing it is stupid.
8:24 i searched lots of places online no one cleared the confusion i had like u did thank you 💚 but there's a question i just wrote a non blocking code of 2B loop spins ... but who is the _owner_ of tye other end here? 😅
Good video, I've a question about processing. let's say I've a node js code that sends some processing intensive calculation to another language for example python, will it run on another thread?
I disagree with respects to multithreading. It can be stupid easy if planned out properly. Granted, my experience with it was with Java, but I was involved in a 10 person team in school whose project was an OpenNap client. Basically an open version of Napster, one of the original peer to peer file apps. One of my tasks was to make the program handle multiple threads safely. We had to as libraries we were using utilized threads to handle multiple download streams. Plus the client had to handle normal peer to peer traffic, searches, and system access, and normal user interface functions all at the same time. All I did was treat the program like a tree and built a gatekeeper object as the trunk. This trunk was the main thread, and it loaded each subsequent portion of the program into their own threads. The trunk held any global data, controlled access to any forms of inter thread communication necessary, and handled non library access to system resources like files and such. Each thread would try to access data outside the thread by asking the trunk for access. If the trunk determined a value was safe for the thread to read or write to, it placed a block on that value for any other thread and granted access. Once the thread was done accessing it, it would notify the trunk and the trunk would free up the value to others. Basically, always check and block before touching data that is available to multiple threads. It is, in my kind always easier to build some code to mediate all this for the threads, so one part of the code is tasked with maintaining thread safety. Then the rest of the code just has to deal with the fact that values may not always be available to acces at the moment the want to. Just, in this case, you can a return value telling you it's not ready yet rather than possibly crashing your program. Then all you have to do is either wait or carry on with other tasks for a bit before checking again. I will say though, I tend to like async programming better myself, but there are languages that deal better with other models.
Now I understand clearly why we use async and await thanks :) but i am using python instead of javascript and the technology is FastAPI it is pretty fast closer to Node js :D
Hi Hussein, the example you gave of brute force using multiprocessing. Is it applicable for multi-threading too? I mean if thread 1 accesses from A-E from the rainbow table, thread 2 accesses from F-J and so on... This is possible I guess... and will it be still thread safe?
Every multiprocessing code can be changed to multithreading but you might not get the same benefits. So for this use case of brute force, which is CPU heavy operation, let's say you spin up 10 threads within a single process which is running on octa core computer. In that scenario, your application is using only 1/8 of your computing power and then dividing it into 10 threads amd in reality your cpu is underutilized. What you could do is spin up 8 processes and then have each process spin up few threads and in this way you get the best out of your cpu
Get my Fundamentals of Networking for Effective Backends udemy course Head to network.husseinnasser.com for a discount coupon (link redirects to udemy with coupon applied)
Man you should start a podcast for this stuff, just put some of it on spotify for us to listen to it in the background. You are so good at explaining these things in such a casual way that you are kinda having a conversation rather then just explaining, thats a real skill. Would love some of this on spotify to listen to while just cleaning up and stuff.
Not only was your explanation informative and served as a great recap of the differences between these paradigms, but you were funny too! Your engaging personality kept me interested for the whole video, and it was over before I realised :)
This is what they always told me at work, understand the basics, understand the basic.. and here I am always ended up getting confused in basic.
And back to ur channel to relearn all those things
Him: does anyone even print stuff these days
The books behind him: ...
You got me
You probably dont care at all but does anyone know of a trick to get back into an Instagram account..?
I was dumb forgot the password. I would appreciate any assistance you can give me!
@@ahmedmalakai9753 If u still did not get back to ur account, it is as simple as clicking forget the password and that will send an email to ur gmail and then create new one for that instagram account !
@@hacker64xfn99 dude probably forgot his youtube account as well lol
@@ahmedmalakai9753 wait ok why are you asking here? This seems like the world's #1 most irrelevant place to ask that question. no shade or anything but like, i mean where did u think it was gonna go?
I clicked the thumb up button after I watched the whole video, and I ended up given all video I've been watched a thumb up in this channel, thank you Hussein!
jiaojie wei thumbs up to you dear 👍 and much love ❤️ thanks for your comments glad you enjoyed the content
I loved this explanation! You might consider doing a podcast when you just chill by yourself or with a guest and start off from some technical subject but treat it casually and with lots of everyday examples, just like you did in this clip. New sub from me and keep it up! :D
dreamer ❤️ thank you for the suggestion ! Appreciate it and welcome to the channel!
@@hnasr Glad to be a member of this community!
@Hussein Nasser I would love to know your opinion about goroutines (Golang) and erlang process
Thanks to the geniuses who made coding so easier for us newbies in the 21st century. Imagine, having to code back in the 70's or 80's, with no software like VS Code that can color code your text, auto complete lines of code, spin up the compiler/interpreter with just a click of a button, handles the communication with the OS, does syntax error check, etc.
All we have to do is just know how to and what to code.
The systems we build now are much more complex 😉
@@hellowill aah yes the code monkeys making another useles webapp
I don't think anybody can explain it in a more better way . Thank you
Great video, as usual.
To summarize: if your app is "i/o bound" (e.g. reading data from a db, and sending it back) then use the asynchronous model (like NodeJS). If you are doing something "cpu bound" (e.g. video processing or cracking passwords) then use something supports subprocesses and channels (like golang).
What do you mean by "and sending it back"? Unlike in real life, data can be in two places at once, so there's no need to send anything back
Hussein the way you express yourself echoing in my mind. I like your passion and professional attitude which are seen rarely together man. True engineer
Thank you Mustafa for the kind words dear ❤️
I was very confused about asynchronous vs. multithreading, and you clarified that a lot in the first 3 minutes. Thank you!
i'm thankful to the people who suffered through callback hell
Who the hell is this guy ??? To this day, this is the best explanation I ever found.
This dude rocks. He talks in a way I can understand, and he's not boring.
Clear and concise explanation, proof that we don't need beautiful architecture drawings when concepts are clear.
I just realized you've got a ps2 on the background, so many good memories of that console
The most amazing, funny, useful. programming information video without coding I have ever seen until now. Amazing brother.
multithreading languages tend to solve the problem by introducing reactive programming, Java did this after the community introduced some technologies like RxJava. and it is very power to combine both in the language echo system. however hard to perceive from the first glance. Great video buddy, all my wishes to you.. keep up bro
Ahmed Daraz thanks Ahmed for the insights! Well said
I just can't stop watching your videos man .... Keep them coming !
Thanks! Enjoy 😊
Also, one of the reasons a lot of people moved to asynchronous programming is performance. Multi threading model, aka 1thread/request or thread pool model, induces a lot of context switching between threads, since everytime a thread blocks it’ll be removed and put back when the blocking operation completes. This operation has a hefty cost at scale, while with asynchronous programming you have a fixed set of threads (generally the number of threads your cpu supports) doing non blocking operations.
First time I felt myself laughing at a programming tutorial/explanation. Thank you for this video!
I love your explanations and as someone who is trying to become a backend engineer, I think your channel is a gold mine of useful information. Keep up with awesome videos!
this is the first time I smiled the whole way through a technical video :)
You're a really good teacher. I admire your talent sir!
welp i just got addicted to this channel i guess
I agree, multithreading is hard to code but it's worth doing especially if you combine it with asynchronous execution
you will have the most responsive, memory-efficient application
I'll go with multiprocessing only when execute a rarely use case with heavy logic
This is hilarious! Please make a podcast - i'd love to wake up to you talking about any programming related topic haha XD
❤️ anchor.fm/hnasr
This was a good watch. I think I see single-threaded async behavior differently now. I am now also very interested in process interop now.
Most of all, I have a weird urge to try working with multiple asynchronous single-threads at the same time.....
Thanks Nasser. Just getting my feet wet with programming, python, turbo_flask, and threading. I appreciate your explanation.
I guess proxies interest you more than anything (They come up at least once in every video of yours) !!!..Btw, I am a fan, and Thank you for the great content
excellent approach & good humor to explain complex topics in a simpler way.
This explanation was something else.....
Thanks man!!!!!
Thanks Hussein for this content. Keep the good work going.....
Like to see u have very less subscriber, but still u r no bother about it.. u just share very unique knowledge on this channel. Which i have never find on other channel. Thank You, keep continue. sharing is caring.
As usual fantastic video Hussein but in multi-processing we have to go with IPCs and the like and we will lose the shared memory space (which exists in multi-threading) among the threads. That is one key need in problems that involve high real-time update-rate. I see what you are saying about the locks and all the headache that comes with them and you nailed it there.
Well said Thanks Osama, good points, one slight addition; you can have shared memory between different processes (postgres is an example) of course you have the same trouble of managing the shared memory
@@hnasr you got it right Mr. I usually go with Redis for more or less and have all my global "shared" variables there. If you are aware of faster alternatives, I am all in. Thx again.
@@hnasr what do you think of green-threads used in Go and all the collaborative scheduling that comes with them. I am planning on taking a deep dive there once we deliver the current project.
Not familiar with Go but heard really good things how Go was built for networking and threading in mind to make it really easy
@@hnasr There is one fantastic talk i recall watching I guess in 2018, it is called the "way of Go" or the "why of Go", highly recommended.
I think you can mix asynchronous and multiprocessing. I did something like that with fastapi using asynchronous functions and a Procfile with different microservices running on different ports
Regarding the multiprocessing use case for password cracking, if that's done on a particular machine, that's pretty much another variant of bitcoin mining ASIC but with different hashing algorithm. And the machine is optimised for this parallel workload.
Imagine him being your mentor! Freakn amazing,
Well, The best explanation I see in my whole life, till today
Your videos are super great! But I prefer the one with graphics and drawings, because I can understand and memorize better informations
Lahdili Zuhir thanks! I agree with you too. I am experimenting with different formats. And i want mix both drawing and talking head 🗣👍
Yes exactly
@@hnasr Even Khan Academy style drawings are good or even basic white board. I feel when things are explained with visuals and the key points are written down then it's easier to absorb the information
Thank you very much Hussein, that was a clear explanation.
Loved this video, the last half of this video could definitely make a great series on ways to use multiprocessing!
Love all your videos, specially about soft skills and motivation one. There are times when I get lost and watching these videos again put me on track and keep going.
A technical Craig Ferguson! Loved it.
Amazing video, finally i learned this topic.
Amazing explanation. Really cleared a lot of doubts.
This is great man, I like your style of teaching! I kind of revise this topic once in a while and I'm going to bookmark this video so I revisit it later on.
It was fun learning and watching this video😆
Excellant explanation, very engaging and concise!
In a real-life scenario, imagine working as a receptionist in a coffee shop.
When working synchronously, you handle one customer at a time, and the line of waiting customers remains inactive until the previous customer receives their order.
Multithreading involves teamwork, where a friend assists in taking orders by opening a second counter. However, the challenge arises as you may end up interrupting each other's work. If done effectively, productivity doubles, but without coordination, the service quality may suffer.
On the other hand, asynchronous work involves taking orders continuously and serving customers as orders are ready. This method ensures smooth service flow as you can efficiently notify customers when their orders are ready while continuously serving the next customer in line.
I love your explanations! Excellent food for thoughts.
Man, I love the enthusiasm you bring to the field!
I love your videos too much! 🥰 They are so deep and teach advanced concepts instead of just showing how to write a "hello world!" In a hell language 😐
Need more ^^
Have this doubt, how would you solve a sudoku using any of the techniques in the least time. Most favourable would be to use multithreading in this case. How to implement it? It is kinda a complicated problem.
Good Explanation!Finally understand these concept quick and good.
Very informative and intuitive explanation! Thanks so much
Java handles multithreading perfectly well, synchronized keywords ensure no 2 thread has access to a method executing a code whilst still in the execution state until the current thread releases the lock. It also avoids deadlocks due to its synchronized nature. I don't know how to implement this in NodeJS.
Very very good explanation, congratulations!
Does i/o controller need different thread if yes then asynchronous == mulithreading?
جزاك الله خيرا ❤️ Thanks
You are such an amazing teacher!!!! I actually kind of understand this now, thanks so much!😍
In your explanation of asynchronous non-blocking flow while waiting for an I/O response, the single-threaded flow does not wait and continues to go on. If the one and only thread did not block and it continues to go on, how is the I/O response got detected? Does it spawn another thread to detect the I/O response? Or does is the one and only thread doing context switching back and forth?
A good example is nodejs, it is a single thread that does an event loop. The thread sends to IO request and moves on to do something else, then it comes back to check if it got a response (polling) the OS. It gets complicated depending on the type of async io the OS supports. Recent linux io_uring is a game changer.
This video might clarify
ruclips.net/video/gMtchRodC2I/видео.html
Nice explanation man, You have 1 new subscriber 👍👍👍
Best explanations ever.
Wow, buddy, it is an amazing explanation. You are awesome!
Very nice explanation! Thank you for this video!
عظمة
كل عام وانتم بخير يا هندسة
Great intuitive explanation !
Very good explanation.. Don't know why so less thumbs-up
In Spanish we have a word for people like you... Chingon! :D
DataSurgeon 369 yay I just googled it and doesn’t mean loco 😍 thanks buddy
smooth explanation .. 5 star
Hey Hussain, Thanks for clearing all the doubts and great explanation, absolutely loved it♥️ especially the event loop 🙂
I did it.... Syntactical sugar😂😂... I love your explanation man.... We are the new generation where we don't write multithreading or async code, we IMPORT libraries to do it for us😂✌️
Best teacher.
loved the explanation - simple and concise
this dude is hot and he makes sense. ok. his channel also has a bunch of solid videos. im rollin with him. will watch every single video in the coming weeks. good stuff.
Salam, i think mixing both is good. I like both multi threaded + asynchronous.. i dont like big event loops or when language doesn't really support await thingy you have to invent your own or bring some library which im not fan of doing so
This was really helpful, informative and to the point. Thanks !
i suspect that some implementations of async & await use multithreading. nice video
Awesome video, thanks man.
Use mixing of Multiprocessing and Async. It will be useful
I have to disagree about staying away from multithreading. They have their own use context, with their pros & cons of course. And so it is that they came up with worker threads in nodejs. But I liked your explanation. Really funny the js event loop part. Regards!!!!
Alain Perez thanks Alain! Loved your point of view
@@hnasr I have become a huge fan of your videos 😊😊😊😊😊
Fantastic explanation. I sense some nginx prior tinkering which got you into this stuff. If you take a deep dive on the read modes async io, direct-io your audience will get much more value. Bravo and keep them coming.
Thanks for creating amazing content..✨
As the old joke goes:
A programmer has a problem. He decides to use threads. has now problem. He two
Good defs, BUT... ;) ... I agree w/the multi-threading bad rap... yes, you have to put some legwork in to get it working right because of easy resource access conflicts. Its not as hard as it sounds though once you understand it. BUT... once you do, this is the most performant way to write code. Mutli-processing is essentially multi-threading at a process level. So you do get the benefits of parallel execution and the speed. BUT, problem is, inter-process communication is SLOOOW. In olden days this was called Out-Proc, vs. In-Proc, was in-process communication. Essentially any communication within the same process boundary is the fastest there is. Any communication across process boundary is MUCH slower, by a factor of 100 or so. So there is a definite downside to multiprocessing vs. multi-threading, IF you want the processes to communicate a lot. If not, then its not an issue. Async/Await, is basically a cheap/simulated multithreading. Its maximizing the use of the single thread, which is awesome, but it will never be as efficient or powerful as multi-threading for obvious reasons. BUT, its the least people should do. Not doing it is stupid.
8:24
i searched lots of places online
no one cleared the confusion i had like u did
thank you 💚
but there's a question
i just wrote a non blocking code of 2B loop spins ... but who is the _owner_ of tye other end here? 😅
So... going with your recommendation of multiprocessing... how do you accomplish that in C#? do you have a video on that?
Good video, I've a question about processing. let's say I've a node js code that sends some processing intensive calculation to another language for example python, will it run on another thread?
Coffee is an option, as a beverage, or a lifestyle
Luv yer energy level
I disagree with respects to multithreading. It can be stupid easy if planned out properly. Granted, my experience with it was with Java, but I was involved in a 10 person team in school whose project was an OpenNap client. Basically an open version of Napster, one of the original peer to peer file apps.
One of my tasks was to make the program handle multiple threads safely. We had to as libraries we were using utilized threads to handle multiple download streams. Plus the client had to handle normal peer to peer traffic, searches, and system access, and normal user interface functions all at the same time.
All I did was treat the program like a tree and built a gatekeeper object as the trunk. This trunk was the main thread, and it loaded each subsequent portion of the program into their own threads. The trunk held any global data, controlled access to any forms of inter thread communication necessary, and handled non library access to system resources like files and such. Each thread would try to access data outside the thread by asking the trunk for access. If the trunk determined a value was safe for the thread to read or write to, it placed a block on that value for any other thread and granted access. Once the thread was done accessing it, it would notify the trunk and the trunk would free up the value to others.
Basically, always check and block before touching data that is available to multiple threads. It is, in my kind always easier to build some code to mediate all this for the threads, so one part of the code is tasked with maintaining thread safety. Then the rest of the code just has to deal with the fact that values may not always be available to acces at the moment the want to. Just, in this case, you can a return value telling you it's not ready yet rather than possibly crashing your program. Then all you have to do is either wait or carry on with other tasks for a bit before checking again.
I will say though, I tend to like async programming better myself, but there are languages that deal better with other models.
Keep up the great work, man!
thank you so much for this good explanation
Nice explanation !!
Now I understand clearly why we use async and await thanks :) but i am using python instead of javascript and the technology is FastAPI it is pretty fast closer to Node js :D
Can you please the same thing with diagrams or animation ?
Hi Hussein, the example you gave of brute force using multiprocessing. Is it applicable for multi-threading too? I mean if thread 1 accesses from A-E from the rainbow table, thread 2 accesses from F-J and so on...
This is possible I guess... and will it be still thread safe?
It is applicable in multithreading yes
@@hnasr okay thanks!
Every multiprocessing code can be changed to multithreading but you might not get the same benefits.
So for this use case of brute force, which is CPU heavy operation, let's say you spin up 10 threads within a single process which is running on octa core computer. In that scenario, your application is using only 1/8 of your computing power and then dividing it into 10 threads amd in reality your cpu is underutilized.
What you could do is spin up 8 processes and then have each process spin up few threads and in this way you get the best out of your cpu
Nice video! Greeting from Costa Rica
Great explanation sir. I like the idea of multiprocessing !!! though never used :p
Wow amazing content and very entertainment. Thank you very much