pthreads #2: Creating multiple threads

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 70

  • @lucasthrelfall679
    @lucasthrelfall679 3 года назад +1

    This might be the best resource on the internet to learn pthreads multithreading. Thank you!

  • @minhazulislam4682
    @minhazulislam4682 2 года назад

    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.

  • @KristonMcConnell
    @KristonMcConnell 3 года назад

    Your videos have been 10x more helpful than the university course that I'm paying $$$$ for

  • @andrewpersaud4144
    @andrewpersaud4144 6 лет назад

    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!

  • @yulianloaiza
    @yulianloaiza 4 года назад +1

    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

    • @majordexter6044
      @majordexter6044 3 года назад +1

      I guess Im pretty randomly asking but do anybody know a good place to watch newly released movies online?

  • @mishalubich7141
    @mishalubich7141 2 года назад

    The best video/resource on multithreading in C! Thank you so much!

  • @kellyrankin8844
    @kellyrankin8844 4 года назад

    Just wanted to say thank you for making this. Nice and calm and easy.

  • @sallytraveler
    @sallytraveler 9 лет назад +23

    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.

    • @arbadon
      @arbadon 9 лет назад

      +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);

    • @sallytraveler
      @sallytraveler 9 лет назад +1

      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 :)

    • @ajanabi5377
      @ajanabi5377 7 лет назад

      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??????????????

    • @theolgd2719
      @theolgd2719 7 лет назад +3

      +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.

    • @bestsaurabh
      @bestsaurabh 6 лет назад

      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.

  • @siddharthpandey8516
    @siddharthpandey8516 7 лет назад +2

    Brilliant explanation for such a complex program....great I found your videos to start multi threaded programming. Thanks! :D

  • @guillermowendy1997
    @guillermowendy1997 6 лет назад +4

    Wow, amazing! You helped me understand multithreading for my homework, thank you!

  • @isaacaskey1410
    @isaacaskey1410 4 года назад +2

    Thank you for this video. Very helpful for understanding thread concurrency!

  • @berekerb3471
    @berekerb3471 5 лет назад

    thanks dr. fraser, it gave me so much clarity

  • @ryanflynn386
    @ryanflynn386 7 лет назад +2

    This is a really great walkthrough! Thanks so much.

  • @SaiMako19
    @SaiMako19 9 лет назад +2

    This is really really helpful!! Very comprehensive! Thank you!!

  • @aravindhravichandran5152
    @aravindhravichandran5152 5 лет назад +1

    Clear and Precise! Thanks a ton!

  • @theolgd2719
    @theolgd2719 7 лет назад +2

    This helped me a whole lot, thank you very much !

  • @GunsofBrixton89
    @GunsofBrixton89 7 лет назад +2

    Thank you, I learned a ton.

  • @SarfarazAhmad89
    @SarfarazAhmad89 7 лет назад

    Thank you Dr. Brian Fraser . Best regards.

  • @ΑντρέαςΣωτηρίου-π8γ
    @ΑντρέαςΣωτηρίου-π8γ 4 года назад +1

    Excellent explanation!

  • @uzielpalavecino1821
    @uzielpalavecino1821 2 года назад

    Hi, excellent video, does anyone know what is the GUI you use to display the threads?

  • @BurhanWani1
    @BurhanWani1 9 лет назад

    Very nice video. how do you move the lines up and down in vim ?

  • @kittuniha
    @kittuniha 4 года назад

    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.

    • @Mattress121
      @Mattress121 4 года назад

      it's a c99 feature called variable length arrary (VLA)

  • @bestsaurabh
    @bestsaurabh 6 лет назад

    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).

  • @Gabriel-iy1zq
    @Gabriel-iy1zq 4 года назад +1

    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?

    • @dipankarpurecha5564
      @dipankarpurecha5564 3 года назад +1

      They still teach this topic in our course so i guess it is.

  • @shafaghkamkar4009
    @shafaghkamkar4009 9 лет назад

    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.

    • @irismelendez4437
      @irismelendez4437 7 лет назад

      Did you ever figure this out? I'm wondering the same thing.

  • @keyofawesomefan
    @keyofawesomefan 9 лет назад +3

    this is amazing! thank you so much!

  • @BenBilesBB-box
    @BenBilesBB-box 5 лет назад

    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.

    • @BenBilesBB-box
      @BenBilesBB-box 5 лет назад

      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.

    • @BenBilesBB-box
      @BenBilesBB-box 5 лет назад

      NO! I cant use exec since it wipes out everything in memory... OK so I have to just run the function from the child.

  • @yonizerbib9934
    @yonizerbib9934 5 лет назад +1

    Thanks from Paris :)

  • @pengren3906
    @pengren3906 7 лет назад

    Awesome! This video helps me a lot!

  • @vickygupta3131
    @vickygupta3131 8 лет назад

    thank you,here, all threads are not running parallel, how can we make them to run parallel?

  • @BullyWiiPlaza
    @BullyWiiPlaza 8 лет назад +3

    Brilliant man, thanks

  • @SUBHASHKUMAR-em2sh
    @SUBHASHKUMAR-em2sh 4 года назад

    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

  • @julytwentyone2744
    @julytwentyone2744 6 лет назад

    sir why is the function in pointer ? with the *?

  • @adarshsunilkumar7095
    @adarshsunilkumar7095 6 лет назад +1

    we are not initializing tids[i] then how it contain unique values ......?

    • @opdiox
      @opdiox 6 лет назад

      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

  • @amirhosseinakbari6648
    @amirhosseinakbari6648 8 лет назад

    it was very helpful .thanks a lot

  • @AlqGo
    @AlqGo 7 лет назад

    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!

  • @ajanabi5377
    @ajanabi5377 7 лет назад

    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??????????????

  • @chrischristos4550
    @chrischristos4550 8 лет назад

    and how can we make multithreading with more than one functions?

    • @Pompiduskus
      @Pompiduskus 8 лет назад

      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 );
      }

    • @ajanabi5377
      @ajanabi5377 7 лет назад

      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??????????????

  • @josecarlos_42
    @josecarlos_42 6 лет назад

    Thank you soooo much!!!

  • @oldchili3154
    @oldchili3154 5 лет назад

    This video is made by GOD

  • @BurhanWani1
    @BurhanWani1 9 лет назад

    sorry that is eclipse. i though you were using vim editor

  • @Jaultaub
    @Jaultaub 7 лет назад

    thanks so much!

  • @Elantry
    @Elantry 4 года назад

    Nice!

  • @nightcoremusic695
    @nightcoremusic695 4 года назад

    thank you

  • @sahilmangotra1214
    @sahilmangotra1214 7 лет назад

    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

  • @sl4807
    @sl4807 5 лет назад +2

    you sound like sal from khan academy

  • @DavidsonQWERTY
    @DavidsonQWERTY 8 лет назад +1

    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.

    • @veooquenodaa
      @veooquenodaa 7 лет назад +1

      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)

    • @DavidsonQWERTY
      @DavidsonQWERTY 7 лет назад

      makes sense, thank you =)

    • @ajanabi5377
      @ajanabi5377 7 лет назад

      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??????????????

    • @ambujsingh5259
      @ambujsingh5259 6 лет назад

      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".

  • @vamsisaikrishna
    @vamsisaikrishna Год назад

    He is not Brian Fraser, he is brain eraser

  • @ajanabi5377
    @ajanabi5377 7 лет назад

    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??????????????

    • @ajanabi5377
      @ajanabi5377 7 лет назад

      hey thanks a lot ........where are you from??

  • @sl4807
    @sl4807 5 лет назад +2

    you sound like sal from khan academy