Multithreading with a Thread Pool in C

แชร์
ฝัง

ความคิดเห็น • 24

  • @76anoopsaxena
    @76anoopsaxena 3 ปีที่แล้ว

    The second argument is an attribute object to the thread where one can configure the new thread for attributes like stack size, address, scheduling policy etc. As NULL, default values are taken. I believe Joshua has correctly described the 4th argument.

    • @76anoopsaxena
      @76anoopsaxena 3 ปีที่แล้ว

      Should have added, pthread_attr_init(pthread_attr_t *attr) initialises this attribute object. This, if used, precedes the call to pthread_create(). And a lovely video. Revisiting threads and threalpool after 20 years!

    • @eom-dev
      @eom-dev  3 ปีที่แล้ว

      This is great, thank you! I'm going to pin your comment so others see it as well :)

  • @johnseed2148
    @johnseed2148 3 ปีที่แล้ว +2

    I think you can have more functions with the same name in different c files if you define them as static

  • @nskeip
    @nskeip 2 ปีที่แล้ว +1

    Nice video! I wonder if we could face a problem when setting thread_pool->active to zero while some thread is reading it. Or it is correct?

  • @joshuawright2125
    @joshuawright2125 3 ปีที่แล้ว +1

    I believe the 4th argument in the pthread_create function is the start routines void * argument

    • @eom-dev
      @eom-dev  3 ปีที่แล้ว

      Thank you - it seems a bit obvious now... Mind if I pin your comment so others can see it? (Not that there is much competition).

  • @76anoopsaxena
    @76anoopsaxena 3 ปีที่แล้ว

    Apologies, I am being intermittent with my comments. One important aspect is one doesn't need to cast a void *. So malloc 'should' not be casted and likewise one can do away with the casting with ThreadJob as well. :)

    • @eom-dev
      @eom-dev  3 ปีที่แล้ว

      I'm finding void pointers are my favorite data type for this very reason. I'm surprised it isn't emphasized as one of the most useful aspects of C!

    • @thebatchicle3429
      @thebatchicle3429 10 หลายเดือนก่อน

      @@eom-devit’s not emphasized because it’s a language feature everyone knows about except for C++ devs

  • @mainfranklin8767
    @mainfranklin8767 2 ปีที่แล้ว

    Would it be better/correct to use pthread_cond_broadcast in the thread_pool_destructor instead of sending that many number of signals with pthread_cond_signal ?

  • @lin2jack2
    @lin2jack2 2 ปีที่แล้ว

    Can you do a topic on atomic ?

  • @serebbi
    @serebbi 2 ปีที่แล้ว

    Are you also coding any other language? Or only C? And if yes, is hat hard to do instead of sticking to just one.

  • @toolb0x_
    @toolb0x_ 2 ปีที่แล้ว

    really like your vids, but please silence the sound of your keyboard ;-)

  • @markmanning2921
    @markmanning2921 3 ปีที่แล้ว

    even at 1080p your micro miniature black fonts on a blinding wall of white make it very difficult to read what you type with my old eyes.

    • @eom-dev
      @eom-dev  3 ปีที่แล้ว

      Haha sorry! I'll keep that in mind for future videos. Thanks for letting me know!

    • @markmanning2921
      @markmanning2921 3 ปีที่แล้ว

      @@eom-dev other than that it all looked good except i couldnt see it very well lol

  • @SuessesSumpfhuhn
    @SuessesSumpfhuhn 3 ปีที่แล้ว

    I think your code is not working.. used you tutorial for creating a threadpool and you cannot use it, if you do not allocate memory for the actual threadpool-struct. furthermore, the struct cannot be used as a return value, you could only return the pointer to the struct. i think malloc is missing here ..

    • @eom-dev
      @eom-dev  3 ปีที่แล้ว

      Are you using the thread_pool_constructor function to create the struct? I designed this shortly after transitioning from C++ and was implementing things with OOP in mind. There should be a function in the library that will set everything up!

  • @frogstud
    @frogstud 8 วันที่ผ่านมา

    A thread pool is like a pool. Too many people and you'll have a bad time. Even though it's not optimal, you might as well swim alone in your own pee

  • @helenesajer9723
    @helenesajer9723 3 ปีที่แล้ว +2

    This code is incorrect and half baked don't waste 45 minutes on this like I did.

    • @liutuoni
      @liutuoni ปีที่แล้ว

      I also found some mistakes. When adding task to the queue, he forgot to aquire the lock and He should add a while loop to check if the queue is empty just before the signal wait statement.