I used to think that all the PhD folks are brilliant at research but they suck at teaching. To be honest, my views have changed after watching your videos. Specially when you talk about errors and how to get rid of them easily. Getting rid of errors is a skill that people take for granted and it costs them in the long run. Thanks for being a nice teacher and making these wonderful videos.
Got perfect on my assignment because of you. More complicated than this but wouldn't have figured out how to organize it and pass data around without this video!
Superb video, your explanation is awesome! To print thread IDs (18:00) all you need to do is to simply cast pthread_t to int: (int)tids[i] and simply printf it using %d.
For sure.. One could also use %ju in conjunction with casting the tids[i] to (uintmax_int) from . (I think this more "by books" approach but feel free to correct me) #include printf("Sum for thread %ju is %ldd ", (uintmax_t)tids[i], args[i].answer); All in all, many options available there :)
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
+rahul more Don't write like this, please, my eyes still hurt. On the topic of your question : he created a structure sum_runner_struct containing two long longs : one for the number to be processed, one for the answer. This way he just had to have each thread put the result in the answer variable. Since each iteration of the struct is local to the main, the data gets there.
Each thread is executing on different data and has a different result. Both these entities- data and result are combined into a complex data type- structure and we have an array of that. Each array element is populated in different threads and we are accessing that in the main thread.
Greate Video, one question how can u create a array with run-time value, ptherad_t pid[num_args], num_args is calculated during run time based on argc. Compiler should throw error and i am wondering how can u run it without issues.
If I put the pthread_join in loop, is it going to wait for 1st thread to complete, then wait for 2nd thread to complete and so on? How can I achieve something like- whichever thread has completed its task, print the result rather waiting for the 3rd thread to finish when the 5th thread has already finished (just an ex).
why moving the pthread_attr_t inside the for loop? By the same argument for creating variables on the stack, in each iteration a new pthread_att_t is generated, while we are not sure if the corresponding thread is done using it yet. So, first why no bug? second, why not leave it outside the for loop in the first place? Thanks for the series, they were very helpful for me.
Hi, is it possible to run a Pthread with a while loop ? I use inotfy.h in linux to monitor a folder for new files. when there is a new file write closed in the folder I process the file but I miss any further new files being created while the program is busy processing the new file against data models. If I process the new files with Pthreads I need to wait for them to complete and so I will still miss picking up a new files arriving in the folder. Much appreciate your videos ! great to have someone walk through pthreads. I was dreading using the structs but you make it much clearer.
after watching the FORK and EXEC videos I think Its better I run inotify in main and fork exec the data processing part of my code. inotify uses public variables so I think I would have to mutex lock them. I'm hoping data I load into the parent memory arrays from file will be accessible by a forked child exec. Also hoping the child exec can execute functions that reside in other external files. I found a forked process can. Thanks again for the videos. I'll post back here if I get inotify watch folder running as a seperate process from the data processing.
Good after noon sir sir how to check odd or even number using pthreads and how to create a factorial number program using threads and how to run both program in on code please help me
I simply don't get why people or even courses that teach C don't teach how a stack works, even though it is VERY simple to understand and has SERIOUS implication on using C pointers. People who don't know stack can very, very easily create dangling pointers in C. Teaching stack is important!
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
Hello ....Nice Video, Actually I need some help,I have a project to make on Critical section Problem in OS. But I don't have enough time to learn everything and then make project , can anyone help me to find topics i need for it. Any help is appreciated , Thanks
I really can do that args[num_args]? seems to be wrong, because the compiler doesn't known the vector size before executing. btw, great video :), helped me alot.
by the time you start the program, num_args will be equal to the amount of numbers the program received, so its not wrong. (its defined somewhere in the middle as int num_args= argc -1)
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
But for running the program you need to first compile it. This program would definitely result in a COMPILE TIME ERROR, something like "expression must have constant value".
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
This might be the best resource on the internet to learn pthreads multithreading. Thank you!
I used to think that all the PhD folks are brilliant at research but they suck at teaching.
To be honest, my views have changed after watching your videos.
Specially when you talk about errors and how to get rid of them easily.
Getting rid of errors is a skill that people take for granted and it costs them in the long run.
Thanks for being a nice teacher and making these wonderful videos.
Your videos have been 10x more helpful than the university course that I'm paying $$$$ for
Got perfect on my assignment because of you. More complicated than this but wouldn't have figured out how to organize it and pass data around without this video!
Wow, thank you so much! I was holed up with passing different data to each thread using a struct for the argument. This helped a lot
I guess Im pretty randomly asking but do anybody know a good place to watch newly released movies online?
The best video/resource on multithreading in C! Thank you so much!
Just wanted to say thank you for making this. Nice and calm and easy.
Superb video, your explanation is awesome!
To print thread IDs (18:00) all you need to do is to simply cast pthread_t to int: (int)tids[i] and simply printf it using %d.
+Stefan V You could also use %u instead of %d to print out the value of a pthread. :)
printf("Sum for thread %u is %ldd
", tids[i], args[i].answer);
For sure.. One could also use %ju in conjunction with casting the tids[i] to (uintmax_int) from . (I think this more "by books" approach but feel free to correct me)
#include
printf("Sum for thread %ju is %ldd
", (uintmax_t)tids[i], args[i].answer);
All in all, many options available there :)
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
+rahul more
Don't write like this, please, my eyes still hurt.
On the topic of your question : he created a structure sum_runner_struct containing two long longs : one for the number to be processed, one for the answer. This way he just had to have each thread put the result in the answer variable. Since each iteration of the struct is local to the main, the data gets there.
Each thread is executing on different data and has a different result. Both these entities- data and result are combined into a complex data type- structure and we have an array of that. Each array element is populated in different threads and we are accessing that in the main thread.
Brilliant explanation for such a complex program....great I found your videos to start multi threaded programming. Thanks! :D
Wow, amazing! You helped me understand multithreading for my homework, thank you!
Thank you for this video. Very helpful for understanding thread concurrency!
thanks dr. fraser, it gave me so much clarity
This is a really great walkthrough! Thanks so much.
This is really really helpful!! Very comprehensive! Thank you!!
Clear and Precise! Thanks a ton!
This helped me a whole lot, thank you very much !
Thank you, I learned a ton.
Thank you Dr. Brian Fraser . Best regards.
Excellent explanation!
Hi, excellent video, does anyone know what is the GUI you use to display the threads?
Very nice video. how do you move the lines up and down in vim ?
Greate Video, one question how can u create a array with run-time value, ptherad_t pid[num_args], num_args is calculated during run time based on argc. Compiler should throw error and i am wondering how can u run it without issues.
it's a c99 feature called variable length arrary (VLA)
If I put the pthread_join in loop, is it going to wait for 1st thread to complete, then wait for 2nd thread to complete and so on? How can I achieve something like- whichever thread has completed its task, print the result rather waiting for the 3rd thread to finish when the 5th thread has already finished (just an ex).
Doctor, you're a wizard at this!! Great video. Now that is 5 years old, just wanted to ask if it was still relevant and useful in practice?
They still teach this topic in our course so i guess it is.
why moving the pthread_attr_t inside the for loop? By the same argument for creating variables on the stack, in each iteration a new pthread_att_t is generated, while we are not sure if the corresponding thread is done using it yet. So, first why no bug? second, why not leave it outside the for loop in the first place?
Thanks for the series, they were very helpful for me.
Did you ever figure this out? I'm wondering the same thing.
this is amazing! thank you so much!
Hi, is it possible to run a Pthread with a while loop ? I use inotfy.h in linux to monitor a folder for new files. when there is a new file write closed in the folder I process the file but I miss any further new files being created while the program is busy processing the new file against data models. If I process the new files with Pthreads I need to wait for them to complete and so I will still miss picking up a new files arriving in the folder. Much appreciate your videos ! great to have someone walk through pthreads. I was dreading using the structs but you make it much clearer.
after watching the FORK and EXEC videos I think Its better I run inotify in main and fork exec the data processing part of my code. inotify uses public variables so I think I would have to mutex lock them. I'm hoping data I load into the parent memory arrays from file will be accessible by a forked child exec. Also hoping the child exec can execute functions that reside in other external files. I found a forked process can. Thanks again for the videos. I'll post back here if I get inotify watch folder running as a seperate process from the data processing.
NO! I cant use exec since it wipes out everything in memory... OK so I have to just run the function from the child.
Thanks from Paris :)
Awesome! This video helps me a lot!
thank you,here, all threads are not running parallel, how can we make them to run parallel?
Brilliant man, thanks
Good after noon sir
sir how to check odd or even number using pthreads and how to create a factorial number program using threads and how to run both program in on code
please help me
sir why is the function in pointer ? with the *?
we are not initializing tids[i] then how it contain unique values ......?
Because he passes the element i of the tids as a reference into the pthread_create function so it assigns it thread id that way
it was very helpful .thanks a lot
I simply don't get why people or even courses that teach C don't teach how a stack works, even though it is VERY simple to understand and has SERIOUS implication on using C pointers. People who don't know stack can very, very easily create dangling pointers in C. Teaching stack is important!
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
and how can we make multithreading with more than one functions?
We can make:
void* func_2(void*);
void* func_3(void*);
void* func_4(void*);
pthread_t pT[ 10 ];
for (i=0; i < 10; i++ ) {
if ( i%2 == 0 )
pthread_create( &pT[i], &pAttr, func_2, &g_var );
else if( i%3 == 0 )
pthread_create( &pT[i], &pAttr, func_3, &g_var );
else if( i%4 == 0 )
pthread_create( &pT[i], &pAttr, func_4, &g_var );
}
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
Thank you soooo much!!!
This video is made by GOD
sorry that is eclipse. i though you were using vim editor
thanks so much!
Nice!
thank you
Hello ....Nice Video,
Actually I need some help,I have a project to make on Critical section Problem in OS. But I don't have enough time to learn everything and then make project , can anyone help me to find topics i need for it.
Any help is appreciated ,
Thanks
you sound like sal from khan academy
I really can do that args[num_args]? seems to be wrong, because the compiler doesn't known the vector size before executing. btw, great video :), helped me alot.
by the time you start the program, num_args will be equal to the amount of numbers the program received, so its not wrong. (its defined somewhere in the middle as int num_args= argc -1)
makes sense, thank you =)
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
But for running the program you need to first compile it. This program would definitely result in a COMPILE TIME ERROR, something like "expression must have constant value".
He is not Brian Fraser, he is brain eraser
i have really big query plzzzzzzz anyone reply me.............all threads are execurting on fdifferent data but how different sums are getting passed to main from thread???.......in first video he was using global variable so it is understood thatr after execution of thread sum gets summed up in for loop and in main simply we print golabal sum.....but here we didnt use gloabal varible for structure and also we didnt pass sums to main from threads then how these sums are getting passsed in main?????????????????????????????????????plzzzzzzzzzz help som,eone??????????????
hey thanks a lot ........where are you from??
you sound like sal from khan academy