RAII for thread pool | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

RAII for thread pool

Hi Refer code below: https://code.sololearn.com/c544GaxL0ec5 I have basically two questions as below: 1. clsThreadPool is my class following RAII? I was suggested to use smart pointer in place of vector but is it necessary at all? 2. clsThreadPool1 is having shared_pointer of thread[] but I am not able to use make_shared for array like below: pThreads = make_shared<thread>()[max_threads]; Every example I came across for shared pointer of array is using new, but i dont want to do that and would like to use make_shared. how to do so? Thanks in advance...!

21st Mar 2022, 6:37 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 1
Thanks GamerGeil Hd . This is another nice way of having threads in shared pointer. However, shared_pointer of vector is not an array. It is dynamically allocated on heap where as shared_ptr array will be on stack. This is the performance degradation we will be getting if we use "shared_pointer of vector of thread" compared to "shared pointer of thread array". Correct ? Also another thing is related to syntax issue i am facing in original code of mine. Thread is also a class in c++ library and hence i thought to have array of thread class as shared_pointer but it has compile error. Thanks again for your time and help.
1st Oct 2023, 8:36 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Np
1st Oct 2023, 8:37 AM
D1M3
D1M3 - avatar