I was extremly tired of seeing every new born kid in youtube teaching C++ while i found your chanel,and I realy like your contents and i found them realy usefull just wanted to say , thank you man .
Very nice explanation. Although I have a few doubts. 1. What is the exact use of the detach function? I mean even if we create the thread and do not call the detach function is it not the same as creating the thread and calling the detach function? 2. Coming to the destructor terminating the program if thread is joinable. The terminator will not be called until the end of the function here, so what is the issue in this case? Why do we need to use join or detach to make it non-joinable so that destructor does not terminate the program. Thanks in Advance
really really very good explanation. I have always confusion with Multi-threading in C++. Looking more videos on threading . Like for experienced persons . As C++ Developer company's always ask for Multi-threading in depth . Thanks alot .
Very good session talking about join vs detach. Will be a good idea to include how the main program can ensure that it is 'live' until the detached thread is running.
Great video! Just I want to mention that when the process is destroyed (when the main function returns) no detached thread can live outside the main process. Furthermore, there is a phase when the process is being destroyed, the detached threads can exhibit undefined behavior if they ever touch static objects or variables of other threads
I think detach example was not really good. You forget to tell that when the main thread finishes, all threads will be stopped. Maybe it will be better to call a thread (t2) of a thread (t1) of the main thread. So when you detach t2 from t1, if t1 finishes, t2 will continue executing unless the main thread will finish.
Hey Rupesh, I went through few of your videos and I really liked them as it helped me in brushing up my basics. You take us to the basics the and explain the things in detail. Thats the way it should be. Couple of suggestions or topics that I am looking forward: 1. Joining the thread created in one class in another 2. Different IPC mechanism(not sure if this is already there) 3. It would be helpful if you can share the code that you are using to explain.(Actually, I need the header information from your code, which is short, sweet and meaningful) 4. Difference between each version of cpp
You're kinda saying it wrong when mentioning that OS is being slow and doesn't execute the run(). The right way to say it is to explain that context switch(thread/process scheduling) depends on the OS scheduler and we cannot say what thread exactly will run at a particular moment. However, we can use locks for mutual exclusion and condition variables for ordering constraints, which were needed in the detach example.
Nice... Easy to understand the concepts using these videos... Thanks for the same.... One doubt that came to mind is what's use case of detach ? As that task might not be completed at all (I thought it would be over after completion of other stuff in other thread or main thread...just detach means don't wait till completion .... Seems this understanding was wrong from my side.... So wandering what case detach usage is advisable)
Good video once again. In case there was a detach for T1 thread, if main reaches the end, then the detached thread wont execute and program will terminate. Would be good to also have an example where T1 thread executes post initialization, control is passed to main thread and after a specified period, T1 kicks in once again.
Hi, I tried to run your code for add even/odd program using visual studio. But surprisingly using thread approach is taking more time than without thread approach. So, Can you share your comment on this? Regards, PK
I am sorry if I missed this but a small confusion, i still couldn't undersand the functionality of detach, so it detachs the thread that we started and start running the parent thread, but if I am not wrong that behaviour would be same if we don't write anything at all ?
Nice Video; When detach will be usefull while doing coding. This is because when parent process/thread is exited; then what is point of having other thread in coding.
i think you got it wrong because either in join or detach case if main thread goes off then join or detach will also go off. We use detach just only for saying that that we are not waiting for this particular thread to complete.
Its an important thought. I also wondered the same. Mainly detached thread is used for some background task to run and we don't care about it after that (its a completely independent thread and we are not interested in waiting for it to finish).
Hi Rupesh, Great thanks for your threading tutorial. There is a question comes in my mind: Shouldn't we consider refactoring when a function is too long to remember whether the thread has been already joined? Is there case that a thread is joined twice/multiple times? Best regards,
@@CppNuts No sir. What I meant was like each main thread can have multiple sub threads. If any of the thread is crashed before main thread completion, then main program will terminate or only that particular thread will get killed. Case1 : when join is mentioned in main. Case2 : when join is not mentioned but added some 1min delay in main.
If you have to return a value from a thread you should look into std::async. async returns a std::future which holds the value returned from the callable object. If you can't use the async route, you could also return values by reference parameters. Make sure to pass your arguments with std::ref(), though. There is also std::promise but I haven't been able to wrap my head around that yet.
Hi everyone, Don't forget to hit LIKE and SUBSCRIBE button for more videos like this!!
And this will help me a-lot.
Hey man, thanks a lot for this tutorial. Randomly picked your channel for understanding thread in code and it was worth it.
I was extremly tired of seeing every new born kid in youtube teaching C++ while i found your chanel,and I realy like your contents and i found them realy usefull just wanted to say , thank you man .
Wow, thanks!
Very nice explanation. Although I have a few doubts.
1. What is the exact use of the detach function? I mean even if we create the thread and do not call the detach function is it not the same as creating the thread and calling the detach function?
2. Coming to the destructor terminating the program if thread is joinable. The terminator will not be called until the end of the function here, so what is the issue in this case? Why do we need to use join or detach to make it non-joinable so that destructor does not terminate the program.
Thanks in Advance
really really very good explanation. I have always confusion with Multi-threading in C++. Looking more videos on threading . Like for experienced persons . As C++ Developer company's always ask for Multi-threading in depth . Thanks alot .
Sure dude!
So so Awesome man. Thanks for the easy-to-follow instructions and guides mate. Thank you
lol you confused me with the while (count --> 0). I thought it was some new syntax.
No it is not.. 😂
yes me as well
The famous --> operator
Me too. I replaced it with the prefix expression, --count in my notes for clarity.
same here :-)
Very good session talking about join vs detach. Will be a good idea to include how the main program can ensure that it is 'live' until the detached thread is running.
Great video! Just I want to mention that when the process is destroyed (when the main function returns) no detached thread can live outside the main process. Furthermore, there is a phase when the process is being destroyed, the detached threads can exhibit undefined behavior if they ever touch static objects or variables of other threads
Thanks.. it will be helpful to everyone..
I think detach example was not really good. You forget to tell that when the main thread finishes, all threads will be stopped. Maybe it will be better to call a thread (t2) of a thread (t1) of the main thread. So when you detach t2 from t1, if t1 finishes, t2 will continue executing unless the main thread will finish.
Amazing sir, thank you. That was so clear to me to understand this information. Easy. Have a nice day.
Glad it was helpful!
Sir you are a genius I'm glad that i found your channel. Superb explanation. Thank you so much 😊
Thanks man!!
Glad i could help..
Hey Rupesh, I went through few of your videos and I really liked them as it helped me in brushing up my basics. You take us to the basics the and explain the things in detail. Thats the way it should be. Couple of suggestions or topics that I am looking forward:
1. Joining the thread created in one class in another
2. Different IPC mechanism(not sure if this is already there)
3. It would be helpful if you can share the code that you are using to explain.(Actually, I need the header information from your code, which is short, sweet and meaningful)
4. Difference between each version of cpp
Thanks Parag, I will try but I am so much busy these days.
Nice video.... waiting for More videos on multithreading c++ 11
Sure man!!
You're kinda saying it wrong when mentioning that OS is being slow and doesn't execute the run(). The right way to say it is to explain that context switch(thread/process scheduling) depends on the OS scheduler and we cannot say what thread exactly will run at a particular moment. However, we can use locks for mutual exclusion and condition variables for ordering constraints, which were needed in the detach example.
really good explanation. looking forward for more vides on multithreading
Sure, many videos are on the way.
Nice... Easy to understand the concepts using these videos... Thanks for the same.... One doubt that came to mind is what's use case of detach ? As that task might not be completed at all (I thought it would be over after completion of other stuff in other thread or main thread...just detach means don't wait till completion
.... Seems this understanding was wrong from my side.... So wandering what case detach usage is advisable)
You sir are a true genius.
Thanks for the comment dude!!
Please continue your good work. Very good explanation. Thanks a lot
Thanks man!!
Hi man, I love the energy from video. Very good explanation :)
could you please suggest any real case example, when we need to detach a thread ?
Good video once again. In case there was a detach for T1 thread, if main reaches the end, then the detached thread wont execute and program will terminate. Would be good to also have an example where T1 thread executes post initialization, control is passed to main thread and after a specified period, T1 kicks in once again.
`while (count --> 0)` is a crime
Hi,
I tried to run your code for add even/odd program using visual studio. But surprisingly using thread approach is taking more time than without thread approach.
So, Can you share your comment on this?
Regards,
PK
I am sorry if I missed this but a small confusion, i still couldn't undersand the functionality of detach, so it detachs the thread that we started and start running the parent thread, but if I am not wrong that behaviour would be same if we don't write anything at all ?
Hey Rupesh , Its really good :) You are doing a good job ,, keep it up :)
Hi Shilpa.. Thank you so much..
Are you the same Shilpa i know?
@@CppNuts yes..
@@CppNuts 😝🤩
Nice Video; When detach will be usefull while doing coding. This is because when parent process/thread is exited; then what is point of having other thread in coding.
i think you got it wrong because either in join or detach case if main thread goes off then join or detach will also go off.
We use detach just only for saying that that we are not waiting for this particular thread to complete.
Its an important thought. I also wondered the same. Mainly detached thread is used for some background task to run and we don't care about it after that (its a completely independent thread and we are not interested in waiting for it to finish).
Awsome Video..You are the Einstein of C++..
kuch jyada nhi ho gaya?
Parvez yee to inka pyar hai yaar, verna me to kuch bhi nahi..
Mere liye C++ ka Einstein to Scott Meyers hai.
He actually deserve this name, not me. 😊
Chandra, Nahi yaar yee bahot badi baat keh di aap ne.
@@CppNuts but Aapke video bahut acche hote hai.. aur easy to understand bhi 🙏
Thanks man! 😊
Why do you need to explicitly detach the thread using detach() that too in main.. while main ends by itself if join() is not used.
thanks so much ...for making youtube video for other ...
Welcome dude..
What is the difference between using t1.detach() and not using join()?
What's with /media/sf_SharedBetweenLinux/CppNuts Tutorial/CppNuts ? Are you running this all off a Pendrive?
Well ! t1.detach() is mentioned to suspend the t1 thread execution then how it is still running inside main() thread ???
Sorry if i understood wrong, but detach() doesn't suspend the thread, it just detach it from the process.
Love your content!
Glad you enjoy it!
Hi Rupesh,
Great thanks for your threading tutorial.
There is a question comes in my mind:
Shouldn't we consider refactoring when a function is too long to remember whether the thread has been already joined?
Is there case that a thread is joined twice/multiple times?
Best regards,
Concurrently calling join() on the same thread object from multiple threads constitutes a data race that results in undefined behavior.
Detach thread can release its resources , so what will be the impact i detached thread using other thread resources
Could you please demonstrate how a thread will terminate the program, if join or detach is not mentioned. Sample code in comment is fine.
i think you didn't get it right because when program dies threads die but thread dont kill program.
Re-watch the video for clarity.
@@CppNuts No sir. What I meant was like each main thread can have multiple sub threads. If any of the thread is crashed before main thread completion, then main program will terminate or only that particular thread will get killed.
Case1 : when join is mentioned in main.
Case2 : when join is not mentioned but added some 1min delay in main.
what if run() returns some value lets say int. how will you return from the func executing by a thread.
Can we detach this_thread in the run().?
If you have to return a value from a thread you should look into std::async. async returns a std::future which holds the value returned from the callable object. If you can't use the async route, you could also return values by reference parameters. Make sure to pass your arguments with std::ref(), though. There is also std::promise but I haven't been able to wrap my head around that yet.
how much i like you when you count points from 0. haha
I'm glad!
Thanks
Sir how to create multi char server client using threads?
Amazing video. You are a superstar
You are the best
🔥superb course
Thanks
is this threading concept used in transaction
can you do videos on inter process communication in c++ please
Sure..
bro Could you please give link for functor?
It's so cursed to see a "while" without curly brackets "{ }"
4:18 just realized you sound like the terminator
😎😎
i saw x-->0 i thought that is it new syntex? and googling but it is x -- and >0 haha
8:21 9:35 10:18
I just cant stand how confidently you say "attends zero" when writing x --> 0 xDDD
Missing Alexa
You remember that.. 😁
Yes😁
The ADs are a little bit too much, which interrupts the thinking of learning
you are doing a great job but why so much ads ?? :(
It's UA-cam not me.
@@CppNuts okayy 🙌🏻
after detach() execution main thread continues running
after join() execution main thread pauses and waits until the new thread ends