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.
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!
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. :)
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 ?
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 ..
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!
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.
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.
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!
This is great, thank you! I'm going to pin your comment so others see it as well :)
I think you can have more functions with the same name in different c files if you define them as static
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?
I believe the 4th argument in the pthread_create function is the start routines void * argument
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).
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. :)
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!
@@eom-devit’s not emphasized because it’s a language feature everyone knows about except for C++ devs
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 ?
Yes
Can you do a topic on atomic ?
Are you also coding any other language? Or only C? And if yes, is hat hard to do instead of sticking to just one.
really like your vids, but please silence the sound of your keyboard ;-)
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.
Haha sorry! I'll keep that in mind for future videos. Thanks for letting me know!
@@eom-dev other than that it all looked good except i couldnt see it very well lol
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 ..
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!
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
This code is incorrect and half baked don't waste 45 minutes on this like I did.
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.