The problem here simple addition is being used +. Load on the CPU is decided based on machine instructions finally. Replace + with say sin(i) function. Then we can say the advantage of thread parallelism over single. I tested and it is working. Also when trying with sin function, reduce last to 190000000(or have floats) otherwise it might take lot of time.
Hi guys, Hope you enjoyed the video, more advance video is coming in few days on thread topic. And please let me know if i can provide something else on this topic. Your support is appreciated. LIKE & SUBSCRIBE for more videos like this.
Hi, I have two questions... can I run the same function with different threads (at the same time obv)? And how should I manage the return of my function? ( something like this "result= thread t0(example,1); " ? )
Thank you for the step-by-step instructions. I did not understand other videos, but you kept it simple and now my program runs in 1:17 and not 5:40. (4 threads) Thank you!. Subbed
We can use "auto duration = duration_cast(stopTime - startTime); " to get the seconds directly instead of getting in micro sec and then dividing it to get in seconds.
Bear in mind, threading doesn't always mean your execution time will be faster. There are a lot of factors that can make threading even slower than serial.
@@linhnguyenthithuy-st7vn I can think of a scenario where we have a CPU with single core and both threads have methods which fully need CPU (no I/O). In that case total time spent = CPU time of 1st + CPU time of 2nd + buffer (due to context switches and saving overheads)
I am using VS Code with MinGw compiler and getting the error message "thread" was not declared. I ensured to copy the code correctly, but the program is not running, any suggestions?
I would never thought that i would discover that with a bitwise operators i could check if a number is odd or even. This makes me wonder the world of possibilities that bitwise operators can give.
There are so many questions about the program not behaving correct on different systems, so i double checked everything and found that if we pass by std::ref which i did then it is some how behaving different in some system, so i have made some changes in program, now instead of std::ref i am sending the old school address and it is working fine. check it out: ideone.com/ypngpe let me know if link is not working i will create another one.
I ran the program given in the above link in Cygwin and it ran in time twice of what it took to run without the threads. More specifically the time for code with threads took 17 seconds and without threads, it took 9 seconds. Is there an issue with running threads in Cygwin?
How are you running thread in sublime text My sublime is giving me this error: In function 'int main()': error: 'thread' was not declared in this scope thread t1(temp); ^~~~~~ error: expected ';' before 't2' thread t2(temp2); ^~ error: 't1' was not declared in this scope t1.join(); error: 't2' was not declared in this scope t2.join(); ^~ [Finished in 668ms]
By default, std::thread copies the arguments you pass into its constructor. When you use references (ull&), it tries to copy the reference. However, references cannot be copied-they must refer to an actual object. To pass references to a std::thread-launched function, you need to explicitly wrap the reference in std::ref(). This tells the thread to pass the argument as a reference, not by copying.
Hi Rupesh, The Spelling of Multithreading is in-correct in the playlist. you can correct it to increase your search results. I liked your cpp lectures and would like to request more advance topics like metaprogramming ,etc more of interview questions at higher experiences related to designs. Thanks..
1. All performance testing should be done in Release. It should be mentioned. (Otherwise 2-threaded version may take longer time to execute). 2. What is the point of duration_cast and then dividing it by 1000000 ? Why not to duration_cast ?
@@pavelkravchenko2810 I have faced same issue.. it was taking almost 2x time with 2 threads. So these are steps that resolved my issue : Editor -- XCode 1) Product -> Scheme -> Edit Scheme -> Change Build Configuration to "Release" 2) Now clean Build -> Run app you will get desired result shown in video.. :)
question, what happens when the second thread finishes first before the first thread? will the t1.join() wait for the t1 to finsh before it can t2.join() wait for the t2? or.... both of this join() will run parallel too?
why it is showing error like:- error: 'thread' is not a member of 'std' Can you please help on this. I am running my code on vs code and minGW compiler installed
This should happen only when you have single core CPU. otherwise i do get comments like yours but can't really think of reasons. I tried myself in 3 different systems and it was giving less time while threading, so no clue, i am sorry for not been able to answer to this question.
Apparently it depends on the system - multithreading isn't always faster for everyone depending on what you're doing. stackoverflow.com/questions/46759930/multithreading-slower-than-single-threading
can you explain what might be happening when I calculate the sums using the main thread print time(comes out to be 8 seconds), when I do it using the 2 threads in the same execution of the program without commenting out the main thread calculation without use of threading it takes me aroudn 11 to 15 seconds via multiple threads then weirdly . But if i comment out the calculation of main thread and then execute just the multiple thread calculation it does almost half the processing time for the calculation. So basically when I execute these two methods exclusively the multithreading results in efficiency else if I execute the 2 scenarios together in the same run the multithreading actually takes more time weirdly ?? This was all when done with debug configuration was debug though when i change config to release I get almost half the execution time with multithreading based approach even when running in the same run
This is a small program that just finds sum of even and odd nuns but when you are coding a large application that has billions of lines of code eg. Google(2 billion lines of code), your program should be as fast as possible and it should be able to do multiple tasks at same time.
My knowledge is from stackoverlfow. i was involved in stackoverflow and used to give answers to people and see the answers for my doubts and there were so many discussion, i learned alot from there.
@@CppNuts Thanks for reply..but is there any specific book or sites u visited earlier in ur initial learnubg phase..if u could throw some light definetly it wud help beginners like me and all
Duede trust me there is nomagic stick, i can tell u one thing only which might be of help. Decide a topic what ever it is and then fuck the internet for hunting more and more about it, thats it you are now master at that topic. Thats All!!
@@CppNutsHi, im getting this error: “Thread is not a member of ‘std’ “. Please help me out with this problem thought my Mingw complier is also up to date that supports C++11 version.
hey man, absolutely love your explanations video's. But if I can give you 1 tip, make your intro sound a little less loud. You have a very calm soft voice, so during the video I turn my volume up but when another video starts playing from your playlists I almost go deaf from your intro sound. But keep up the good work, loads of love from a jr. developer in holland
I wrote exactly same code visual studio its taking 21 seconds without thread concept by using 2 separate threads as you did its taking double 40 seconds.. its happening ulta...
There are so many questions about the program not behaving correct on different systems, so i double checked everything and found that if we pass by std::ref which i did then it is some how behaving different in some system, so i have made some changes in program, now instead of std::ref i am sending the old school address and it is working fine. check it out: ideone.com/ypngpe let me know if link is not working i will create another one.
sir I wrote the same code, I gave start=0, end=2000000000 (=2B) but in my case multithreaded code took 37 seconds wherease normal code took 28 second....why?
Thanks for making this video. It was very helpful. However, when I ran the code, shown in the video as well as mentioned in the above link, it takes more time when use thread compared to when I don't. For example, for the code mentioned at the above link, it takes 7 seconds to execute the code with threading; while it takes 6 seconds when I'm not using threading!! (I'm running the code using VSCode in Ubuntu 16.04) Do you have any idea? Why it's happening? Thanks again :)
Sir i have a question, lets say we have 10 threads and we want them to be able to pick up a job dynamically, (assuming we have 15 callable functions), how can we dynamically pass the name of functions and parameters? Do threads accept function names stored in variables?
C++ threading class may be cool, but nothing like using the native Linux pthread_create() like POSIX APIs to manage your threads, also note that not all thread related services are in the c++ class, for example, pthread_cond_wait(), signal and broadcast APIs which helps a producer thread to wake up waiting consumer threads. Perhaps in the case of writing highly portable c++ code, might be useful to use the thread class. any thoughts?
I am surprised by seeing the result in my VS2015, without threads it took 9secs and with two threads it took 20Secs for the same program.It's strange..
@@srinu571 No idea about visual studio, i have verified in Mac and Linux. May be some day i will run using visual studio and see if there is something i can do to overcome this.
In the single-threaded version, the entire task is performed on a single thread without the overhead of managing additional threads. The CPU executes instructions sequentially without the need to switch contexts or synchronize memory.
Ok so I'm having some weird behavior in here. I tried the non-threaded program and it executed in 11 seconds. I then tried the threaded program and it went to 15 seconds. I then tried to change the program so oddSum and evenSum are local variables passed by pointer (the rectified version posted in the comments) and now the program sometimes executes in 13 seconds and sometimes in 6.3 seconds. So first why did the first multithreaded program execute slower than the non-threaded program ? Second why did the change from global to local variables change the execution time ? And finally why would the rectified program have different execution time even though it's the same executable file ? If it helps I'm running on Linux on a computer with an i3 processor (it should be 4 logical cores).
@@Sandroidus Hey thank you. I just tried with -O2 and -O3. -O2's execution time is now around 4 seconds while -O3 is around 3.8 seconds. Thank you so much.
With the below program the timing issue will be solved: The problem is passing reference in thread, If reference and pointers removed it will work. Below is the program #include #include #include #include using namespace std; using namespace std::chrono; typedef long long int ull; void findEven(ull start, ull end, ull EvenSum) { for (ull i = start; i
Actually i don't have git code for this video but i am planning for a website where i will keep all the code i use in videos, and that will take some time.
It worked for me in Visual Studio 2019. (Code from Link in description) But the time take is different at every run. (I am running in Debug x86 configuration) Its 10s, 26s, 30s...
Hello sir, Where do I get the source code of all of your TH-cam playlist. Will we get all source code after joining on your patreon page. Once after joining patreon, all source codes will be visible or those will be provided on request. Please let me know. Thanks for providing these amazing content video on CPP.
I crosschecked many times and pasted your code also but same result... With thread.. it takes 13 secs but Without thread it takes 10 secs.. how ?????
Did you took latest code i updated in video details.
I have provided link.
@@CppNuts Yes rupesh... latest one from link where you are passing reference of OddSum and EvenSum instead of making them global variable....
Then no idea why is it like this.
I have 3 system i check in every system but not getting this issue.
The problem here simple addition is being used +. Load on the CPU is decided based on machine instructions finally. Replace + with say sin(i) function. Then we can say the advantage of thread parallelism over single. I tested and it is working. Also when trying with sin function, reduce last to 190000000(or have floats) otherwise it might take lot of time.
creating a thread is quite an CPU intensive task. So for simple straight forward functions on an older CPU is not always faster when threaded
Hi guys,
Hope you enjoyed the video, more advance video is coming in few days on thread topic.
And please let me know if i can provide something else on this topic.
Your support is appreciated.
LIKE & SUBSCRIBE for more videos like this.
Your efforts are really appreciated and is helpful for many of us.
@@WithHumble Thanks man, it really motivates to create more videos.
Hi, I have two questions... can I run the same function with different threads (at the same time obv)?
And how should I manage the return of my function? ( something like this "result= thread t0(example,1); " ? )
That comes with future and promise topics in cpp, i will start soon.
@@CppNuts thanks, I need it so much... :) Anyway why didn't you used "using namespace std;" it is so useful...
Explained in simple way. Way better than other multi-threading tutorials. Kudos to you guys.
Thanks man!!
Thank you for the step-by-step instructions. I did not understand other videos, but you kept it simple and now my program runs in 1:17 and not 5:40. (4 threads) Thank you!. Subbed
Great.. Things like this encourages me like anything.. 😍🤓
This is quite interesting!! It took 6 sec on my computer without threading, and with threading, it took 3 sec. Thank you so much for the tutorial.
This was so high quality, simple and understandable. Bro, you should teach somewhere, u are gifted.
thank you! you’ve explained this so well. feeling more confident about threads already
Amazing Rupesh... This i would call a social service....Keep it up... Clear cut explanation. God bless you...
Thanks man..
We can use "auto duration = duration_cast(stopTime - startTime); " to get the seconds directly instead of getting in micro sec and then dividing it to get in seconds.
I absolutely love how he drew his channel logo at the end, you're cool 😎❤️
Thanks..
Bear in mind, threading doesn't always mean your execution time will be faster. There are a lot of factors that can make threading even slower than serial.
True..
@@CppNuts could you tell me some cases when threading is slower than others
@@linhnguyenthithuy-st7vn I can think of a scenario where we have a CPU with single core and both threads have methods which fully need CPU (no I/O). In that case total time spent = CPU time of 1st + CPU time of 2nd + buffer (due to context switches and saving overheads)
I am using VS Code with MinGw compiler and getting the error message "thread" was not declared. I ensured to copy the code correctly, but the program is not running, any suggestions?
I would never thought that i would discover that with a bitwise operators i could check if a number is odd or even. This makes me wonder the world of possibilities that bitwise operators can give.
hello, i wanted to thank you for keeping it simple! the example is great, as well as the explanation! keep it up! cheers!
Thanks dude..
There are so many questions about the program not behaving correct on different systems, so i double checked everything and found that if we pass by std::ref which i did then it is some how behaving different in some system, so i have made some changes in program, now instead of std::ref i am sending the old school address and it is working fine.
check it out: ideone.com/ypngpe
let me know if link is not working i will create another one.
Hi Rupesh, with threads and without threads the execution time is same no difference,
What is the configuration of your computer?
@@CppNuts i5 processor with 8Gb of ram
We have to setup program one I have explained in video and one I have given in the link so, in both the cases is it same or it's different.
I ran the program given in the above link in Cygwin and it ran in time twice of what it took to run without the threads. More specifically the time for code with threads took 17 seconds and without threads, it took 9 seconds. Is there an issue with running threads in Cygwin?
Very useful. This subject is very interesting, i hope you'll talk more about it in your next videos. Keep up with good work.
Sure man, and thanks for the comment.
How are you running thread in sublime text
My sublime is giving me this error:
In function 'int main()':
error: 'thread' was not declared in this scope
thread t1(temp);
^~~~~~
error: expected ';' before 't2'
thread t2(temp2);
^~
error: 't1' was not declared in this scope
t1.join();
error: 't2' was not declared in this scope
t2.join();
^~
[Finished in 668ms]
bhai have you got this issue fixed?? please help me, i am also facing this issue
Im facing the same issue as well if you have already found out the way to resolve it plz help me out.
@@daewanshbansal6173 bro at that time instead of fixing my ide i used online gdb compiler...
I really like the way how you explain things. Thank you so much.
Very eloquently explained, great Vid. Subbed!
Salutes from a Chinese fellow engineer
Thanks dude..
By default, std::thread copies the arguments you pass into its constructor.
When you use references (ull&), it tries to copy the reference.
However, references cannot be copied-they must refer to an actual object.
To pass references to a std::thread-launched function, you need to explicitly wrap the reference in std::ref().
This tells the thread to pass the argument as a reference, not by copying.
Hi Rupesh,
The Spelling of Multithreading is in-correct in the playlist. you can correct it to increase your search results. I liked your cpp lectures and would like to request more advance topics like metaprogramming ,etc more of interview questions at higher experiences related to designs. Thanks..
Hey Brajraj, in title it's correct.
Have I missed somewhere in description?
Thanks
1. All performance testing should be done in Release. It should be mentioned. (Otherwise 2-threaded version may take longer time to execute).
2. What is the point of duration_cast and then dividing it by 1000000 ? Why not to duration_cast ?
Pls explain about the testing in Release, cuz I have this result with 2 X time 🤷♀️
@@pavelkravchenko2810 I have faced same issue.. it was taking almost 2x time with 2 threads. So these are steps that resolved my issue :
Editor -- XCode
1) Product -> Scheme -> Edit Scheme -> Change Build Configuration to "Release"
2) Now clean Build -> Run app
you will get desired result shown in video.. :)
Superbb explanation sir. I will never miss yr videos 😍😍😍
Thanks for your support man!!
question, what happens when the second thread finishes first before the first thread? will the t1.join() wait for the t1 to finsh before it can t2.join() wait for the t2? or.... both of this join() will run parallel too?
Yes it will wait.
why it is showing error like:- error: 'thread' is not a member of 'std' Can you please help on this. I am running my code on vs code and minGW compiler installed
My multithreaded program took more time than sequential one. Why would that be happening?
This should happen only when you have single core CPU. otherwise i do get comments like yours but can't really think of reasons.
I tried myself in 3 different systems and it was giving less time while threading, so no clue, i am sorry for not been able to answer to this question.
Apparently it depends on the system - multithreading isn't always faster for everyone depending on what you're doing.
stackoverflow.com/questions/46759930/multithreading-slower-than-single-threading
@@CppNuts does CPU know to spawn the new thread in a new core for parallelism or in the same core for concurrency? How is that decided?
I just love all your videos and teaching sir... Grt😍👍
Glad to hear that
loved it, best explanation done
Hi sir
Can you please explain me if two threads are trying to access same code in singalton class in C++ please I humble request to you
when you were interrupted, it was a perfect example of threading
Yes that's correct !!
showing undefined reference to pthread_creat() any idea how to tackle it... i just copied the code in vim and run `g++ -std = c++17 f1.cpp -o c1`
doing in virtual machine
resolved to use `g++ -std=c++17 f1.cpp -pthread -o c1`
can you explain what might be happening when I calculate the sums using the main thread print time(comes out to be 8 seconds), when I do it using the 2 threads in the same execution of the program without commenting out the main thread calculation without use of threading it takes me aroudn 11 to 15 seconds via multiple threads then weirdly .
But if i comment out the calculation of main thread and then execute just the multiple thread calculation it does almost half the processing time for the calculation.
So basically when I execute these two methods exclusively the multithreading results in efficiency else if I execute the 2 scenarios together in the same run the multithreading actually takes more time weirdly ??
This was all when done with debug configuration was debug though
when i change config to release I get almost half the execution time with multithreading based approach even when running in the same run
In visual studio 2022 debug mode, multithreading does not have any speed benefits for this piece of code. Are there any experts here?
Hi,
In my laptop, above code is taking 46 sec and with thread 25 sec.
any idea why this much slow ?
Intel i7 HQ6820 @2.7Gz and RAM 48 GB
I think it's fine.
How old is it? I don't think that cpu should be performing that poorly
Why there is need of creating 2 threads? We already have one thread main() which can do say findEven and we can create only one thread for findOdd
This is a small program that just finds sum of even and odd nuns but when you are coding a large application that has billions of lines of code eg. Google(2 billion lines of code), your program should be as fast as possible and it should be able to do multiple tasks at same time.
Well explained sir.
Your work is appreciated
Thanks man!!
Hey Rupesh, which CPP editor are you using?
It's VS Code.
Not working on raspberry pi 3 :( Error from g++ undefined reference to `pthread_create'
can you please tell me how to compile it? And what changes we need to make if we want to run it in .c format?
Hello sir could u plss share some resources from where u get these things..that will be helpful
My knowledge is from stackoverlfow. i was involved in stackoverflow and used to give answers to people and see the answers for my doubts and there were so many discussion, i learned alot from there.
@@CppNuts Thanks for reply..but is there any specific book or sites u visited earlier in ur initial learnubg phase..if u could throw some light definetly it wud help beginners like me and all
Duede trust me there is nomagic stick, i can tell u one thing only which might be of help.
Decide a topic what ever it is and then fuck the internet for hunting more and more about it, thats it you are now master at that topic. Thats All!!
There is only one website.
Google.com
😊😊
Ravi Correct!!
Where can I get all these sample?
very good example, perfect explanation
Thanks for the comment man!
can anyone help to debug this below error
error: 'thread' is not a member of 'std'
How r you compiling?
Command ?
which compiler are you using?
I am using MinGW and it's showing an error :(
on Windows 10
Error?
Can you paste it?
Did you got the error?
I am also getting error on using thread
@@CppNutsHi, im getting this error:
“Thread is not a member of ‘std’ “. Please help me out with this problem thought my Mingw complier is also up to date that supports C++11 version.
i need implementation thread and fork can you help im looking someone implement i need understand how its work please help
ok.. but after we make threading, how many thread did the program made? is it parent thread main() and 2 child threads?
what specification were you using?
Great video. Greetings from Spain
Thanks
getting error like this, using c++17
error: 'thread' is not a member of 'std'
hey man, absolutely love your explanations video's. But if I can give you 1 tip, make your intro sound a little less loud. You have a very calm soft voice, so during the video I turn my volume up but when another video starts playing from your playlists I almost go deaf from your intro sound. But keep up the good work, loads of love from a jr. developer in holland
I was wonder if that is an issue. Thanks for the tip.
very nice and simple explanation
I wrote exactly same code visual studio
its taking 21 seconds without thread concept
by using 2 separate threads as you did its taking double 40 seconds..
its happening ulta...
Me too
@@mariam_barghout same
@@MemoirsOfADrainCleaner same
You're running in debug mode. Switch to release
@@Sandroidus How can I switch to release?
Sir What happens if a Thread finishes before OS calls Join( ). Does Thread joins the main program even in that situation ?
Hi,
I have un issue. My programme needs 12 sec to execute without threads and 19sec to execute with threads. Can somebody explain me why?
same in my case.
You're running in debug mode. Switch to release
Hi Sir, which IDE you used in video's? I am looking the same IDE ? is it available for Windows or Mac?
I have used Sublime text editor 3.
But this is editor you will have to link compiler with it.
And it available in mac n windows both.
Hi, I have an issue program without use of thread takes 8sec and the one with thread takes 13-17 sec. My laptop have an i5-9300H processor.
There are so many questions about the program not behaving correct on different systems, so i double checked everything and found that if we pass by std::ref which i did then it is some how behaving different in some system, so i have made some changes in program, now instead of std::ref i am sending the old school address and it is working fine.
check it out: ideone.com/ypngpe
let me know if link is not working i will create another one.
@@CppNuts This link is not working
You're running in debug mode. Switch to release
Can you please tell me which IDE this is?
Hi just found your channel. thanks man lovin it.
Thanks man, i am out of station, next threading video will come around next week.
Beautifully explained!
Glad you think so!
Do you have any video on thread that explains thread scheduling techniques
No, i may have in future, thanks for the topic.
sir I wrote the same code, I gave start=0, end=2000000000 (=2B)
but in my case multithreaded code took 37 seconds wherease normal code took 28 second....why?
Thanks for making this video. It was very helpful.
However, when I ran the code, shown in the video as well as mentioned in the above link, it takes more time when use thread compared to when I don't. For example, for the code mentioned at the above link, it takes 7 seconds to execute the code with threading; while it takes 6 seconds when I'm not using threading!! (I'm running the code using VSCode in Ubuntu 16.04)
Do you have any idea? Why it's happening?
Thanks again :)
same prob with me...
and its also giving this output OddSum 950000000
EvenSum 950000001
Sir i have a question, lets say we have 10 threads and we want them to be able to pick up a job dynamically, (assuming we have 15 callable functions), how can we dynamically pass the name of functions and parameters? Do threads accept function names stored in variables?
Sir what is idle trigger
how can i send you email with something related to patreon? different offer
You can mention here
Very nice series. Please continue to make some great content. Can you make a series on ipcs n socket programming
Explanation was great that helps keep doing good work thanks
Thanks for the encouragement dude!!
Excellent vedio which can be easily understood
Thanks
very much nicely explained !!
wow, this is really nice demo & explanation, thanks
Thanks dude..
You're just awesome mate. Thanks a lot
you said it, I love C++! And I love Hindi!
my M1 Mac is taking 8 see without thread and 2 sec with thread why?
It is good right?
C++ threading class may be cool, but nothing like using the native Linux pthread_create() like POSIX APIs to manage your threads, also note that not all thread related services are in the c++ class, for example, pthread_cond_wait(), signal and broadcast APIs which helps a producer thread to wake up waiting consumer threads. Perhaps in the case of writing highly portable c++ code, might be useful to use the thread class. any thoughts?
If portability is what you need the most then you can go with C++ otherwise POSIX is great choice.
sir how to get these code?
Please make tutorial on C++ boost library. There aren't many tutorials online and also your channel focuses on C++
Can you provide me the video on spin lock in thread
Sure, wait for some time.
I am surprised by seeing the result in my VS2015, without threads it took 9secs and with two threads it took 20Secs for the same program.It's strange..
Please check the code link in description field.
@@CppNuts Even with this new code (Passing evensum and odd sum address and taking as pointer in functions) taking more time 28 sec
@@srinu571 No idea about visual studio, i have verified in Mac and Linux.
May be some day i will run using visual studio and see if there is something i can do to overcome this.
switch to release. never check performance in debug mode.
In the single-threaded version, the entire task is performed on a single thread without the overhead of managing additional threads. The CPU executes instructions sequentially without the need to switch contexts or synchronize memory.
Can you Share the link (GitHub/any other URL) for the code used in the vedio. Is there any vedio for C++20?
I have started writing, will post ASAP it is done.
No i don't have c++20 video for now but will cover it in near future.
Hi, guys. In QtCreator it only works in release mode. If you put debug mode you will see a bigger time.
you explaination is unbaeatable
Font not clear with black background.
So sorry to hear that!!
Ok so I'm having some weird behavior in here. I tried the non-threaded program and it executed in 11 seconds. I then tried the threaded program and it went to 15 seconds. I then tried to change the program so oddSum and evenSum are local variables passed by pointer (the rectified version posted in the comments) and now the program sometimes executes in 13 seconds and sometimes in 6.3 seconds.
So first why did the first multithreaded program execute slower than the non-threaded program ? Second why did the change from global to local variables change the execution time ? And finally why would the rectified program have different execution time even though it's the same executable file ?
If it helps I'm running on Linux on a computer with an i3 processor (it should be 4 logical cores).
You're running in debug mode. Switch to release
@@Sandroidus Hey thank you. I just tried with -O2 and -O3. -O2's execution time is now around 4 seconds while -O3 is around 3.8 seconds.
Thank you so much.
it takes double time after thread ???
Check other comments
Can you please create interview question series on threading?
Can you make a video on gui in C++ ?
really need it thanks
I never worked on GUI in c++, so it will be little hard for me.
I have worked but with QT and that was very basic, won't help much here.
@@CppNuts make video of qthead
Dude what IDE are you using?
VS Code
@@CppNuts on the video we can see Sublime Text, not VS Code
What's your source of knowledge ? I mean what do you read , which book you follow ? Which resources you follow for learning C++
Nice explaination, thank you sir
Welcome..
Do you know about Devise Driver Programming?
No man i am from software side.
With the below program the timing issue will be solved:
The problem is passing reference in thread, If reference and pointers removed it will work.
Below is the program
#include
#include
#include
#include
using namespace std;
using namespace std::chrono;
typedef long long int ull;
void findEven(ull start, ull end, ull EvenSum) {
for (ull i = start; i
can you also provide git repo link
Actually i don't have git code for this video but i am planning for a website where i will keep all the code i use in videos, and that will take some time.
finally got it!! thank you :)
You are most welcome..
does thread work in windows?
Yes..
I love c++ ♥️. Because,it power the world.
thank you a lot, you're a life saver
Glad it helped!
Very useful content Rupesh. Can I get source code snippets explained in videos, if I join with a skilled membership.
Yaa you will get for sure..
I joined your channel as a skilled member. could you please share link for source code snippets explained in the videos. Thank you very much Rupesh.
Thankss for joining the channel..
And sure.. I will be able to give by Tomorrow..
Do u have GitHub account, please create if not and give me userid.
@@CppNuts My github userid: khasimgithub123
It worked for me in Visual Studio 2019. (Code from Link in description)
But the time take is different at every run.
(I am running in Debug x86 configuration)
Its 10s, 26s, 30s...
Great video! Just dont know why on my pc it is slower with threads..
No clue, same with other's too.
I tested it with 3 different pc i have it was faster.
You're running in debug mode. Switch to release
Hello sir, Where do I get the source code of all of your TH-cam playlist. Will we get all source code after joining on your patreon page. Once after joining patreon, all source codes will be visible or those will be provided on request. Please let me know. Thanks for providing these amazing content video on CPP.