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 ?????
@CppNuts
4 жыл бұрын
Did you took latest code i updated in video details. I have provided link.
@cid007007
4 жыл бұрын
@@CppNuts Yes rupesh... latest one from link where you are passing reference of OddSum and EvenSum instead of making them global variable....
@CppNuts
4 жыл бұрын
Then no idea why is it like this. I have 3 system i check in every system but not getting this issue.
@likethat111
4 жыл бұрын
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.
@sebasman1000
4 жыл бұрын
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
@nitishjaiswal
4 жыл бұрын
Explained in simple way. Way better than other multi-threading tutorials. Kudos to you guys.
@CppNuts
4 жыл бұрын
Thanks man!!
@ShivaVRGames
2 жыл бұрын
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.
@Sandroidus
4 жыл бұрын
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
3 жыл бұрын
Pls explain about the testing in Release, cuz I have this result with 2 X time 🤷♀️
@cid007007
3 жыл бұрын
@@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.. :)
@edwin3928ohd
4 жыл бұрын
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
@CppNuts
4 жыл бұрын
Great.. Things like this encourages me like anything.. 😍🤓
@NotJaazmine
11 ай бұрын
thank you! you’ve explained this so well. feeling more confident about threads already
@digikiwam
3 жыл бұрын
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.
@CppNuts
3 жыл бұрын
True..
@linhnguyenthithuy-st7vn
Жыл бұрын
@@CppNuts could you tell me some cases when threading is slower than others
@jayantjain2210
9 ай бұрын
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]
@CppNuts
5 жыл бұрын
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.
@WithHumble
5 жыл бұрын
Your efforts are really appreciated and is helpful for many of us.
@CppNuts
5 жыл бұрын
@@WithHumble Thanks man, it really motivates to create more videos.
@s-a-k-e1814
4 жыл бұрын
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); " ? )
@CppNuts
4 жыл бұрын
That comes with future and promise topics in cpp, i will start soon.
@s-a-k-e1814
4 жыл бұрын
@@CppNuts thanks, I need it so much... :) Anyway why didn't you used "using namespace std;" it is so useful...
@chavhanshrihari3461
4 жыл бұрын
Amazing Rupesh... This i would call a social service....Keep it up... Clear cut explanation. God bless you...
@CppNuts
4 жыл бұрын
Thanks man..
@user-ii2hp9tp1z
2 жыл бұрын
I absolutely love how he drew his channel logo at the end, you're cool 😎❤️
@CppNuts
2 жыл бұрын
Thanks..
@Byynx
6 ай бұрын
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.
@timmyxuereb3083
Жыл бұрын
when you were interrupted, it was a perfect example of threading
@CppNuts
Жыл бұрын
Yes that's correct !!
@andreiasimas2984
Жыл бұрын
Hi, guys. In QtCreator it only works in release mode. If you put debug mode you will see a bigger time.
@teetanrobotics5363
4 жыл бұрын
Please make tutorial on C++ boost library. There aren't many tutorials online and also your channel focuses on C++
@scutursula7536
5 жыл бұрын
Very useful. This subject is very interesting, i hope you'll talk more about it in your next videos. Keep up with good work.
@CppNuts
5 жыл бұрын
Sure man, and thanks for the comment.
@nusud
4 жыл бұрын
hello, i wanted to thank you for keeping it simple! the example is great, as well as the explanation! keep it up! cheers!
@CppNuts
4 жыл бұрын
Thanks dude..
@harounlouati6602
Жыл бұрын
I really like the way how you explain things. Thank you so much.
@bhargavkumar5412
4 жыл бұрын
Hey Rupesh, which CPP editor are you using?
@CppNuts
4 жыл бұрын
It's VS Code.
@khurramsaqib5890
2 жыл бұрын
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?
@srinu571
4 жыл бұрын
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..
@CppNuts
4 жыл бұрын
Please check the code link in description field.
@srinu571
4 жыл бұрын
@@CppNuts Even with this new code (Passing evensum and odd sum address and taking as pointer in functions) taking more time 28 sec
@CppNuts
4 жыл бұрын
@@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.
@Sandroidus
4 жыл бұрын
switch to release. never check performance in debug mode.
@user-mu2qq3eb7t
4 жыл бұрын
you said it, I love C++! And I love Hindi!
@abhishekkumar-os5ey
2 жыл бұрын
I love c++ ♥️. Because,it power the world.
@shaikthouheed9158
2 жыл бұрын
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
@nitigya
2 жыл бұрын
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
@Nohomosapien
2 жыл бұрын
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.
@nageshtuppad6736
5 жыл бұрын
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...
@mariamalbarghouti4385
4 жыл бұрын
Me too
@MemoirsOfADrainCleaner
4 жыл бұрын
@@mariamalbarghouti4385 same
@abhishek3835
4 жыл бұрын
@@MemoirsOfADrainCleaner same
@Sandroidus
4 жыл бұрын
You're running in debug mode. Switch to release
@1chimaruGin0_0
3 жыл бұрын
@@Sandroidus How can I switch to release?
@amargandhi1137
4 жыл бұрын
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
@amentothatt
3 жыл бұрын
Very eloquently explained, great Vid. Subbed!
@amentothatt
3 жыл бұрын
Salutes from a Chinese fellow engineer
@CppNuts
3 жыл бұрын
Thanks dude..
@akashtiwari78059
8 ай бұрын
you explaination is unbaeatable
@user-xw6ns6ih5f
2 ай бұрын
walking up by alexa is cool
@ayushmaankaul6742
3 жыл бұрын
My multithreaded program took more time than sequential one. Why would that be happening?
@CppNuts
3 жыл бұрын
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.
@fang8660
3 жыл бұрын
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
@experimentalhypothesis1137
5 жыл бұрын
very good example, perfect explanation
@CppNuts
5 жыл бұрын
Thanks for the comment man!
@sebasman1000
4 жыл бұрын
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
@CppNuts
4 жыл бұрын
I was wonder if that is an issue. Thanks for the tip.
@nikhilkontam9988
2 жыл бұрын
Can you please create interview question series on threading?
@qichengu9202
11 ай бұрын
In visual studio 2022 debug mode, multithreading does not have any speed benefits for this piece of code. Are there any experts here?
@adityasahu96
3 жыл бұрын
getting error like this, using c++17 error: 'thread' is not a member of 'std'
@user-ky6vq6hj8y
10 ай бұрын
loved it, best explanation done
@alfoom6922
2 жыл бұрын
Great video. Greetings from Spain
@CppNuts
2 жыл бұрын
Thanks
@prajwaldeepkhokhar7416
2 жыл бұрын
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?
@Durgasivakumaran
3 жыл бұрын
I just love all your videos and teaching sir... Grt😍👍
@CppNuts
3 жыл бұрын
Glad to hear that
@himanshurajpal7842
3 жыл бұрын
What's your source of knowledge ? I mean what do you read , which book you follow ? Which resources you follow for learning C++
@govindkothari7989
4 жыл бұрын
Well explained sir. Your work is appreciated
@CppNuts
4 жыл бұрын
Thanks man!!
@rampandi9302
5 жыл бұрын
Superbb explanation sir. I will never miss yr videos 😍😍😍
@CppNuts
5 жыл бұрын
Thanks for your support man!!
@ka-hp4qf
Жыл бұрын
Excellent vedio which can be easily understood
@CppNuts
Жыл бұрын
Thanks
@nishantdhingra5985
4 жыл бұрын
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?
@bestganesh
3 жыл бұрын
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...
@nandhannandhan8155
4 жыл бұрын
Font not clear with black background.
@CppNuts
4 жыл бұрын
So sorry to hear that!!
@toutsujet
5 жыл бұрын
Very nice video, thancks, it helps beginner like me
@CppNuts
5 жыл бұрын
Thanks for your comment man!! I love when someone write that my videos are helping.
@shruthiv4566
4 жыл бұрын
Very nice series. Please continue to make some great content. Can you make a series on ipcs n socket programming
@editprousama
5 жыл бұрын
Can you make a video on gui in C++ ? really need it thanks
@CppNuts
5 жыл бұрын
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.
@toutsujet
5 жыл бұрын
@@CppNuts make video of qthead
@mokera3801
4 жыл бұрын
which compiler are you using? I am using MinGW and it's showing an error :(
@mokera3801
4 жыл бұрын
on Windows 10
@CppNuts
4 жыл бұрын
Error? Can you paste it?
@deepjyotsinghkapoor1955
3 жыл бұрын
Did you got the error? I am also getting error on using thread
@chandravirsingh1184
5 жыл бұрын
Hi Sir, which IDE you used in video's? I am looking the same IDE ? is it available for Windows or Mac?
@CppNuts
5 жыл бұрын
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.
@sagardeka2158
4 жыл бұрын
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?
@milan_shah
4 жыл бұрын
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 :)
@lucidlynxxx
3 жыл бұрын
same prob with me...
@lucidlynxxx
3 жыл бұрын
and its also giving this output OddSum 950000000 EvenSum 950000001
@ChandraShekhar-by3cd
5 жыл бұрын
Hello sir could u plss share some resources from where u get these things..that will be helpful
@CppNuts
5 жыл бұрын
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.
@ChandraShekhar-by3cd
5 жыл бұрын
@@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
@CppNuts
5 жыл бұрын
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!!
@iamravishank
5 жыл бұрын
There is only one website. Google.com 😊😊
@CppNuts
5 жыл бұрын
Ravi Correct!!
@antonfernando8409
2 жыл бұрын
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?
@CppNuts
2 жыл бұрын
If portability is what you need the most then you can go with C++ otherwise POSIX is great choice.
@rajeevdas8213
4 жыл бұрын
Do you have any video on thread that explains thread scheduling techniques
@CppNuts
4 жыл бұрын
No, i may have in future, thanks for the topic.
@AjayKumar-kg6vo
2 жыл бұрын
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
@everythingcelebrity6296
4 жыл бұрын
Dude what IDE are you using?
@CppNuts
4 жыл бұрын
VS Code
@patrykpotorak4296
4 жыл бұрын
@@CppNuts on the video we can see Sublime Text, not VS Code
@nickpratap9161
8 ай бұрын
Thanks
@animetunes8963
6 ай бұрын
what specification were you using?
@fenikatharotiya4333
Жыл бұрын
very much nicely explained !!
@bhagwatjadhav94
5 жыл бұрын
Hi just found your channel. thanks man lovin it.
@CppNuts
5 жыл бұрын
Thanks man, i am out of station, next threading video will come around next week.
@thegoddessgeek1190
2 жыл бұрын
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?
@CppNuts
2 жыл бұрын
Yes it will wait.
@hiranyakeshara1146
3 жыл бұрын
please add a video of image processing using posix threads
@sony1979iq
3 жыл бұрын
ok.. but after we make threading, how many thread did the program made? is it parent thread main() and 2 child threads?
@abelashenafi6291
Жыл бұрын
You're just awesome mate. Thanks a lot
@vvpChannel3112
3 жыл бұрын
Sir What happens if a Thread finishes before OS calls Join( ). Does Thread joins the main program even in that situation ?
@AmitParopkari
3 жыл бұрын
wow, this is really nice demo & explanation, thanks
@CppNuts
3 жыл бұрын
Thanks dude..
@nitinverma1421
5 жыл бұрын
Explanation was great that helps keep doing good work thanks
@CppNuts
5 жыл бұрын
Thanks for the encouragement dude!!
@mizel_1121
3 жыл бұрын
i need implementation thread and fork can you help im looking someone implement i need understand how its work please help
@himalayasinghsheoran1255
4 жыл бұрын
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.
@CppNuts
4 жыл бұрын
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.
@srinu571
4 жыл бұрын
@@CppNuts This link is not working
@Sandroidus
4 жыл бұрын
You're running in debug mode. Switch to release
@avadhpatel111
4 жыл бұрын
Beautifully explained!
@CppNuts
4 жыл бұрын
Glad you think so!
@sebastienleroux3122
Жыл бұрын
Not working on raspberry pi 3 :( Error from g++ undefined reference to `pthread_create'
@il4w
Жыл бұрын
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
@yukinohana9366
2 жыл бұрын
Nice explaination, thank you sir
@CppNuts
2 жыл бұрын
Welcome..
@raxit2684
3 жыл бұрын
Alexa learning to program herself!
@CppNuts
3 жыл бұрын
Correct..
@thotabharadwaj307
6 ай бұрын
why is my system taking 15 seconds to execute with threads and 5 seconds without threads
@user-np7eb4fy3w
4 жыл бұрын
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?
@himalayasinghsheoran1255
4 жыл бұрын
same in my case.
@Sandroidus
4 жыл бұрын
You're running in debug mode. Switch to release
@lucasrfma
3 жыл бұрын
Hey guys, I was having the same problem I see many of you talk about here: Single thread 9seconds, 2 threads = 14seconds. Checking the comments I saw someone talk about debug and release modes and how to change that in the IDE he uses, so I searched about it on google: Try compiling using g++ -O3 filename or g++ -Ofast filename Using the -Ofast I got 2.3seconds single thread, 1.17 seconds 2-threads. Did NOT see that coming haha. There are some explanations about this stuff here: gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
@CppNuts
3 жыл бұрын
OS?
@lucasrfma
3 жыл бұрын
@@CppNuts w10
@yogeshvishnole1264
3 жыл бұрын
Super video sir very very thanks.
@CppNuts
3 жыл бұрын
Welcome dude..
@vijayasajwan2830
5 жыл бұрын
Can you Share the link (GitHub/any other URL) for the code used in the vedio. Is there any vedio for C++20?
@CppNuts
5 жыл бұрын
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.
@roopasaini5679
3 жыл бұрын
Text is not visible properly.it is blur
@tanveerasif5978
3 жыл бұрын
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
@CppNuts
3 жыл бұрын
I think it's fine.
@fang8660
3 жыл бұрын
How old is it? I don't think that cpu should be performing that poorly
@sameermishra8810
2 жыл бұрын
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`
@sameermishra8810
2 жыл бұрын
doing in virtual machine
@sameermishra8810
2 жыл бұрын
resolved to use `g++ -std=c++17 f1.cpp -pthread -o c1`
@ghostknight3175
3 жыл бұрын
my M1 Mac is taking 8 see without thread and 2 sec with thread why?
@CppNuts
3 жыл бұрын
It is good right?
@muhndkalil9234
3 жыл бұрын
Thank you for this video
@CppNuts
3 жыл бұрын
My pleasure
@subee128
Жыл бұрын
Thanks
@teetanrobotics5363
4 жыл бұрын
Bro please make more videos during this period ?
@CppNuts
4 жыл бұрын
I have to do work from home, and i get more tired. But today one video is coming. And you are right i should try more during this period.
@bhargavpatel4781
3 жыл бұрын
Sir what is idle trigger
@awaisnawaz2791
3 жыл бұрын
Can you please tell me which IDE this is?
@user-cq4zk8mw6r
12 күн бұрын
Hello man.
@shailendraprasad2190
3 жыл бұрын
Hello sir, Where do I get the source code of all of your KZitem 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.
@praveenojha33
4 жыл бұрын
I made 4 functions and calculated sum of evens between start to mid from fun1, mid+1 to en from fun2 and similarly I calculated sum of odds from st to mid and mid +1 to en using fun3 and fun4 , I also used 4 different variables to sum the values so that resources are also separate but I did not get better results but even slow results than that of single thread. On my machine Using a single thread whole calculation was performed in 8 seconds , using 2 threads the calculation was performed in 4 seconds but using 4 threads the calculation took 9 seconds !!!. What am I missing ???
@CppNuts
4 жыл бұрын
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.
@milan_shah
4 жыл бұрын
@@CppNuts nope, even the code at this link is not working properly in my machine. I'm using VSCode in Ubuntu 16.04. In my machine, without threading, it's taking 6 seconds to execute while with threading, it takes 7 seconds!!! I don't know what am I missing. Could you please share your further insights? Thank you :)
@anushaboora2876
2 жыл бұрын
Use "Export threads=number of threads" before excecuting your actual prgrm and also if your task is doing better with 2 threads and going for more than that will increase time as time is wasted in maintaining threads or waiting for threads to join...
@kinkajou23
4 жыл бұрын
thank you a lot, you're a life saver
@CppNuts
4 жыл бұрын
Glad it helped!
@karimmuhammad149
4 ай бұрын
when i replaced my sync code to thread code, took more time XD lmao, why my luck like that in always
@bhaskarchary6683
3 жыл бұрын
Where can I get all these sample?
@amargandhi1137
4 жыл бұрын
Can you provide me the video on spin lock in thread
@CppNuts
4 жыл бұрын
Sure, wait for some time.
@codevoitrachhaha1928
3 жыл бұрын
I'm vietnammess, I not good english. But your vidio is very nice.
Пікірлер: 297